HOLES in the text

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;
}

Take a look at letter Q :slight_smile:

Q==1 hole…

I didn’t get it :slight_smile:

Thanks. I missed onto that one, I assumed that we just have to consider the letters given in the question only, Well and what about the validations are we supposed to perform them or what? And even after adding the condition for Q it says wrong answer

why making question so complex buddy…just take string and iterate over it…no need of 2d array…

It seems that you are completely new to competitive programming, right? You don’t need to do any validation - input should be correct and valid, and if it isn’t - well, that’s fail of author, and it should be fixed; and you don’t need to do stuff like you did with 2d-arrays - you may output answers to testcases right after reading them. Your output is a different stream from your input, so only relative order of your answer matters, but it is ok to output some answers before reading whole input.

Well yes completely rt, I am a novice in the world of competitive programming, But I would like to add that it is really fun plus frustrating for me, I hope to learn a lot here, and for 2-D array, I thought we should first take the input and only then print all the o/p together thats why i used a 2-D array.
Thanks a lot for the help mate :slight_smile: HOPE TO LEARN A LOT from the experts here

So now you got what to do or still there is problem…You can ask if still there is any doubt

See brother what i can suggest you is that its better to see solution than to get frustrated.If you are a novice just see 2-3 accepted solution and you will get comfortable with the platform.You will get things like using int main instead of void main(),not using conio and similar things.So just see few solution after having a thought over a question

Yes Thanks a lot for all the suggestions. The way we share knowledge in this information age has been completely revolutionized by internet bringing the world a lot together, Thanks