Professional Documents
Culture Documents
Codechef Beginner qn2
Codechef Beginner qn2
C Programming
Code-Chef Submission
QUESTION: 2: TICKETS5
BEGINNER
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.
//ANANDHA KRISHNAN.R
#include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
char str[100],c1,c2;
int i, check =1;
scanf("%s",str);
c1 = str[0];
c2 = str[1];
if(c1 != c2)
{
for(i=2;i<strlen(str);i+=2)
{
if(str[i] != c1)
{
check = 0;
}
}
for(i=3;i<strlen(str);i+=2)
{
if(str[i] != c2)
{
check = 0;
}
}
}
if(check == 1 && c1!=c2)
printf("YES\n");