Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Wednesday, October 5, 2016

Alternating Characters





Solution :


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
int n,counter;
    char str[100000];
    scanf("%d",&n);
    while(n--)
        {
        counter=0;
        scanf("%s",str);
        for(int i=0;i<strlen(str);i++)
            {
            if(str[i]==str[i+1])
                {
                counter++;
            }
        }
        printf("%d\n",counter);
    }
    return 0;
}

0 Comments:

Post a Comment

Stats