#include
using namespace std;
int main()
{
char str[100];
gets(str);
int i=0,count=0,t;
scanf("%d",&t);
while(t--)
{
while(str[i] != NULL)
{
switch(str[i])
{
case 'A':count+=1;break;
case 'D':count+=1;break;
case 'O':count+=1;break;
case 'P':count+=1;break;
case 'Q':count+=1;break;
case 'R':count+=1;break;
case 'B':count+=2;break;
}
i++;
}
printf("%d",count);
}
return 0;
}
Hey,
I can spot a mistake that you are not resetting the variables i, count inside the while loop for test cases.
After the first test case is completed, the next input is taken. Here variable - i still has the value of the length of the previous input. So continuing with that value of i, str[i] may never become NULL.
Also you are not taking input for the next string in the loop.
Reset both i, count, take input; it should solve your problem. Enjoy coding!
You are welcome. Mark the answer correct and close the question.