Saturday, August 18, 2018

MIKES WORK


  • Problem Description

    Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.

    Mike believes that the day will be successful in case exactly two different letters in the code alternate. Otherwise, he believes that the day will be unlucky. Please see note section for formal definition of alternating code.

    You are given a ticket code. Please determine, whether the day will be successful for Mike or not. Print ""YES"" or ""NO"" (without quotes) corresponding to the situation.
    Input

    The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

    The first and only line of each test case contains a single string S denoting the letter code on the ticket.
    Output

    For each test case, output a single line containing ""YES"" (without quotes) in case the day will be successful and ""NO"" otherwise.
    Note
    Two letters x, y where x != y are said to be alternating in a code, if code is of form ""xyxyxy..."".
    Constraints

    1 <= T <= 100
    S consists only of upper-case Latin letters

    Subtask 1 (50 points):

    |S| = 2

    Subtask 2 (50 points):

    2 <= |S| <= 100
  • CODING ARENA
  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      int t,sl,i,f;
      char str[101],fc,sc;
      scanf("%d",&t);
      while(t--)
      {
        scanf("%s",str);
        sl=strlen(str);
        fc=str[0];
        sc=str[1];
        f=1;
        
        for(i=0;i<sl;i=i+2)
        {
          if(str[i]!=fc)
          {
            f=0;
            break;
          }
        }
          if(f==1){
            for(i=1;i<sl;i=i+2)
            {
              if(str[i]!=sc)
              {
                f=0;
                break;
              }
            }
          }
          if(fc==sc)
            f=0;
          if(f==1)
            printf("YES\n");
          if(f==0)
            printf("NO\n");
      }
      return 0;
    }
        
        
  • Test Case 1

    Input (stdin)
    2
    
    ABABAB
    
    ABC
    
    
    Expected Output
    YES
    
    NO
  • Test Case 2

    Input (stdin)
    3
    
    ABAAA
    
    AAAAA
    
    AAAAA\\\"
    
    
    Expected Output
    NO
    
    NO
    
    NO

No comments:

Post a Comment