Chandu and Consecutive Letters

QUESTION

Chandu is very fond of strings. (Or so he thinks!) But, he does not like strings which have same consecutive letters. No one has any idea why it is so. \n\nHe calls these strings as Bad strings. So, Good strings are the strings which do not have same consecutive letters. \nNow, the problem is quite simple. Given a string S, you need to convert it into a Good String.\n\nYou simply need to perform one operation – if there are two same consecutive letters, delete one of them.\n\nInput:\nThe first line contains an integer T, denoting the number of test cases.\nEach test case consists of a string S, which consists of only lower case letters.\n\nOutput:\nFor each test case, print the answer to the given problem.\n\nConstraints:\n1 <= T <= 10\n1 <= |S| <= 30.

ANSWER

#include <stdio.h>
 
 
int main()
{
    int n=0,i=0,j=0,k=0;
    char a[30];
    scanf("%d",&n);
 
    for(;i<n;i++)
    {
         scanf("%s",a);
         for(;a[k]!='\0';k++)
         {
         	if(a[k]!=a[k-1])
         	{
         		printf("%c",a[k]);
         	}
         }
         k=0;
         printf("\n");
        
  		 
    }
    return 0;
}
 
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.