I’m a newbie.Please,be patient and tell me what is wrong with my approach.
Regardless of what I enter as no. of test cases,only 1 input is accepted and no. of holes are not shown.
#include
using namespace std;
int b,t,i,c;
char d[40];
int holes(char a[40])
{
b=0;
for(i=0;a[i]!=NULL;i++)
{
if((a[i]==‘A’)|(a[i]==‘D’)|(a[i]==‘O’)|(a[i]==‘P’)|(a[i]==‘Q’)|(a[i]==‘R’))
b+=1;
else if(a[i]==‘B’)
b+=2;
}
return b;
}
int main()
{
cin>>t;
i=0;
while(i<t)
{
gets(d);
c=holes(d);
cout<<c;
i++;
}
return 0;
}
Your code will produce WA for 2 two reasons. You are not making c=0 for every input and the 2nd thing is, you are not checking for s[i]==‘O’. I have debugged your code. Check it here Nhgdqs - Online C++0x Compiler & Debugging Tool - Ideone.com
Because it is given in the problem statement that ‘The length of the text is less then 100’. Your previous code was trying to access an element of the string which is out of it’s range.