holes in the text....i am not getting the right answer....what's wrong with my code??

#include<stdio.h>
#include<string.h>
int main()
{

int count=0,i,t,j;
scanf("%d",&t);
char str[100];
for(i=0;i<=t;i++)
{
	gets(str);
}

for(i=1;i<=t;i++)
{

	for(j=0;j<strlen(str);j++)
	{
		if(str[j]=='A'||str[j]=='B'||str[j]=='D'||str[j]=='O'||str[j]=='P'||str[j]=='Q'||str[j]=='R')
		count++;
	
	}
	printf("%d\n",count);
	count=0;
}
return 0;

}

For the letter ‘B’ , you should count 2 holes…

Here are the points you need consider:

  1. Use of gets() has buffer issues, use scanf("%s",str); instead of gets(str);

  2. For ‘B’ there are 2 holes.

  3. The question says that you are supposed to take input of t strings and calculate the answer for each of these strings in t lines. But you are just overwriting str t+1 times and then generating the answer for the last string input t times.


Read the question carefully and try to understand what exactly does the problem statement wants.

I have corrected your solution,here’s the link: http://www.codechef.com/viewsolution/4164640

I would suggest that you first give the question your best try and if you are still unable to solve the problem then refer to the solution.

Happy Coding!

Or use scanf with “\n” like this,

scanf("%d\n",&t);

char str[100];

for(i=0;i<=t;i++)
{

gets(str);

}

hey still i am not getting the right answer.I am getting the output for only the last input that i have entered…

thats because of gets function , you can use cin or scanf to take input of string…

thanks…i got it…!!!

thanks…!!