Tuesday 31 July 2018

Alternating Code
It is IPL Season and the first league match of Dhilip’s favorite team, "Chennai Super Kings". The CSK team is playing at the IPL after 2 years and like all Dhoni lovers, Dhilip is also eagerly awaiting to see Dhoni back in action.

After waiting in long queues, Dhilip succeeded in getting the tickets for the big match. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.

Dhilip believes that the CSK Team will win the match in case exactly two different letters in the code alternate. Otherwise, he believes that the team might lose. Please see note section for formal definition of alternating code.

You are given a ticket code. Please determine, whether CSK Team will win the match or not based on Dhilip’sconviction. Print "YES" or "NO" (without quotes) corresponding to the situation.

Note:
Two letters x, y where x != y are said to be alternating in a code, if code is of form "xyxyxy...".


Input Format:
First and only line of the input contains a string S denoting the letter code on the ticket.

Output Format:
Output a single line containing "Yes" (without quotes) based on the conditions given and "No" otherwise.
Refer sample input and output for formatting specifications.


Sample Input1:
ABABAB
Sample Output1:
Yes

Sample Input2:
ABC
Sample Output2:
No


Solution:
 #include<stdio.h>
#include<string.h>
int main()
{
    int i;
    char a[50];
    scanf("%s",a);
    for(i=0;(a[i]!='\0');i++)
    {
        if(a[i]!=a[i+2]||a[i+2]=='\0'||a[i]==a[i+1])
        break;
    }
    if((a[i+2]=='\0'))
    printf("Yes");
    else
    printf("No");
    return 0;
 }

1 comment:

Random password generator in Java

       Random password generator in Java Source code: mport java.io.*; import java.util.*; public class Main { public static void main(Str...