HOLES IN TEXT

this code runs well for given test case …but gives runtime error.Please help

#include<stdio.h>
int main()
{
     char b[20];
     int i=0,c=0,t=0;
     scanf("%d",&t);
     while(t--)
     {
     c=0;
     i=0;
     scanf("%s",b);
     while (b[i]!='\0')
     {
     if (b[i]=='A'||b[i]=='D'||b[i]=='O'||b[i]=='P'||b[i]=='R')
     {
     c++;
     }
     else if(b[i]=='B')
     {
     c+=2;
     }
     i++;
     }
     printf("%d",c);
     }
     
     return 0;
}

see the constraints of the input string…it is upto 100…so increase ur array size to 101(1 extra for ‘\0’) and the RE will vanish…also u may have missed a letter(which will cause a WA)…hope this helps…:slight_smile:

1 Like

firstly it is always preferrable to declare the array a bit more than what was asked…if the limit is 100 then it is more preferable to declare the size as 150 or something…next thing is that as @kunal361 said check the entire alphabets you have missed 1 case…
happy coding…:slight_smile:

Hey, You know what you are missing one more alphabet with a hole.I won’t tell,I made the mistake of not including it but got AC after adding it. Write down all the alphabets and see which one are you missing.
Further array size is less than constraints.