wrong answer holes in text

#include
#include<stdio.h>
#include<string.h>
using namespace std;

int main(){
int z[40],r,q,c=0;
char p[100];
cin>>q;
for( int i=0;i<q;i++){
gets(p);
r=strlen(p);
for(int j=0;j<r;j++){

if(p[j]=='A'||p[j]=='D'||p[j]=='O'||p[j]=='P'||p[j]=='Q'||p[j]=='R'){
c++;
}
else{
if(p[j]=='B'){
c=c+2;}
}
}
z[i]=c;
c=0;

}
for(int n=0;n<q;n++){
cout<<z[n];
cout<<endl;}
return 0;
}

plzz

this is ur corrected soln…

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
//from discuss...to debug!!!
int main(){
int z[41],r,q,c=0;
char p[101];     // 1 extra space for '\0'..null terminator for strlen fxn!!!
cin>>q;
getchar();     // clear the buffer for gets fxn!!!
for( int i=0;i<q;i++){
gets(p);
r=strlen(p);
for(int j=0;j<r;j++){

if(p[j]=='A'||p[j]=='D'||p[j]=='O'||p[j]=='P'||p[j]=='Q'||p[j]=='R'){
c++;
}
else{
if(p[j]=='B'){
c=c+2;}
}
}
z[i]=c;
c=0;

}
for(int n=0;n<q;n++){
cout<<z[n];
cout<<endl;}
return 0;
}

use a getchar after “cin>>q” to consume the next line character in the buffer.when u press enter after reading q,gets reads the next line character in the buffer which u dnt desire to.so always use getchar() or fflush(stdin) to aoid this problem