Hi Guys
I’ve recently started solving question on code-chef and this Holes in my text is only third problem which I solved, The question says that
Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For example letters “A”, “D”, “O”, “P”, “R” divide the plane into two regions so we say these letters each have one hole. Similarly, letter “B” has two holes and letters such as “C”, “E”, “F”, “K” have no holes. We say that the number of holes in the text is equal to the total number of holes in the letters of the text. Help Chef to determine how many holes are in the text.
Input
The first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. The length of the text is less then 100. There are no any spaces in the input.
So are we not supposed to validate that T must be less than 40 and each string be non-empty contaning of only upper case characters in the problem, cause i looked at some of the solution to the problem and none if them did these validation, So are we supposed to validate the input data or not and
Here is my code It is giving the correct o/p for sample test cases but it is not accepted as the right answer, Can anyone review the code
#include <stdio.h>
int main()
{
int test_times,j=0,lower=1;
scanf("%d",&test_times);
if(test_times<=40)
{
int i,y;
char holes[test_times][100];
for(i=0;i<test_times;++i)
{
if(fscanf(stdin,"%s",&holes[i]));
}
for(i=0;i<test_times;++i)
{
for(;holes[i][j]!='\0';++j)
{
if(!(holes[i][j]>=65&&holes[i][j]<=91))
{
lower=0;
break;
}
}
}
if(lower)
{
for(i=0;i<test_times;++i)
{
int count=0;
for(j=0;holes[i][j]!='\0';++j)
{
//printf("%c",holes[i][j]);
if(holes[i][j]=='A'||holes[i][j]=='D'||holes[i][j]=='O'||holes[i][j]=='P'||holes[i][j]=='R')
++count;
else if(holes[i][j]=='B')
count=count+2;
}
printf("%d\n",count);
}
}
}
return 0;
}