#include<stdio.h>
int main()
{
char arr[100];
int t,i,j,count=0;
scanf("%d",&t);
for(j=0;j<t;j++)
{
scanf("%s",arr);
i=0;
while(arr[i]!=’\0’)
{
if(arr[i]==‘A’||arr[i]==‘D’||arr[i]==‘O’||arr[i]==‘P’||arr[i]==‘Q’||arr[i]==‘R’)
{
count++;
}
else if(arr[i]==‘B’)
{
count=count+2;
}
i++;
}
printf("%d\n",count);
}
return 0;
}
You should initialize count=0 at the beginning of each test case i.e. in your for loop. Else, the count of the previous test case is getting added up with that of the next. Like this:
http://www.codechef.com/viewsolution/3731597