Showing posts with label Bob and Bombs Hacker Earth Solution in C. Show all posts
Showing posts with label Bob and Bombs Hacker Earth Solution in C. Show all posts

Monday, 31 August 2020

Bob and Bombs Hacker Earth Solution in C

 


https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/bob-and-bombs-cake-walk/submissions/

#include<stdio.h>
int main ()
{
int tc,i,j,k,wd,len,x,y;
scanf("%d",&tc);
while(tc--)
{
wd=0;
char str[100000];
scanf("%s",&str);
len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i]=='W'&& i+1 < len &&str[i+1]=='B')
{
wd++;
str[i]='#';
}
else if(str[i]=='W'&& i>=1 && str[i-1]=='B')
{
wd++;
str[i]='#';
}
else if(str[i]=='W'&& i+2 < len &&str[i+2]=='B')
{
wd++;
str[i]='#';
}
else if(str[i]=='W'&& i>=2 && str[i-2]=='B')
{
wd++;
str[i]='#';
}
}
printf("%d\n",wd);
}
return 0;
}