Holes in the text

What wrog with this code!

#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	int counter=0,sum=0;
	int T,n;
	char string[100];
	cout<<"Number of the words: "<<endl;
	cin>>T;

	if(T<=40)
	{
		cout<<"Enter the word: "<<endl;
		
		do
		{
			gets(string);
			n=strlen(string);
			for(int i=0;i<n;i++)
			{
				if(string[i]=='A' || string[i]=='O' || string[i]=='D' || string[i]=='P' || string[i]=='R' || string[i]=='Q') counter++;
				if(string[i]=='B') counter+=2;
				sum+=counter;
			}
			T--;
		
		}while(T>=0);
		cout<<"Number of holes: "<<sum<<endl;
		
	
	}
	else
		cout<<"You enter wrong number!"<<endl;

	return 0;
}

you just hav to print ans…
as in…
cout<<sum<<endl;
dont write any text …

Hi, @vjozic
In any online environment, be it codechef or spoj or topcoder never ever use user prompts unless you are told to! Always follow the strict input and output formats specified!

Look at the test cases given carefully! Simply take the number of cases, strings and output number of holes for each case in new line, is what you are asked to do!

So, remove all prompts like "Enter the word: " and "Number of holes: " etc.

Expcet that, in a quick look, your logic seems to be correct! Try removing extra lines as i mentioned it should work! Let me know if it doesn’t!

Hope this helps! :slight_smile:

2 Likes

You can have a look at this video: http://www.youtube.com/watch?v=fm7tTWy-H-E This teaches us to submit the first problem on the CodeChef online judge.

Thx it works :slight_smile:

@vjozic then you should mark the answer as correct.

1 Like