#include
#include
#include<string.h>
int main()
{
int i,len=0,count,test,j;
char a[101];
cin>>test;
for(j=1;j<=test;j++)
{
cin>>a;
while(a[len]!='\0')
{
len++;
}
count=0;
for(i=0;i<len;i++)
{
if(a[i]=='A' || a[i]=='D' || a[i]=='P' || a[i]=='Q' || a[i]=='R' || a[i]=='O')
count++;
else
if(a[i]=='B')
count=count+2;
}
cout<<count<<endl;
}
return 0;
}
@codecrawler : Why are you checking for ‘\0’ . The new line character is ‘\n’ .
Set len = 0 “inside” the first for-loop.
1 Like
bipin2
November 19, 2013, 7:10pm
4
just find the length of your string using strlen() function
thnx…i will try…let me know…i should use this code
while(a[len]!=’\0’)
{
len++
}
for calculating string length or strlen fn. and why?
@codecrawler …use of above method is good…use it…strlen does the same thing(SO )…u save time of calling a fxn…though it is not a lot…but an optimization is an optimization…
1 Like
zealf
November 19, 2013, 5:54pm
7
i think he is finding length of string in this case(so increasing value till a null character is met)
also using namespace std is missing
bipin2
November 19, 2013, 10:38pm
8
you can reduce your code and stress…
For strlen hope yo know the syntax…
Happy coding…