HOLES - Editorial

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;
}

#include

using namespace std;

int main()
{
int t,i=0;
char text[101];
int holes=0;
scanf("%d",&t);
gets(text);
while(t–){
fgets(text,100,stdin);
while(text[i]){
cout<<"\n\t ch:"<<text[i];
if(text[i]==‘A’||text[i]==‘O’||text[i]==‘P’||text[i]==‘D’||text[i]==‘R’||text[i]==‘Q’)
holes++;
else if(text[i]==‘B’)
holes+=2;
i++;
}
i=0;
printf("%d\n",holes);
holes=0;
}
return 0;
}

WA can some one help y ?

@pradeep_gill post link to your submission, the above format is unreadable.

http://www.codechef.com/viewsolution/3107692

@s1h33p check this nw buddy ?

Those are just examples.

#include<stdio.h>
#include<malloc.h>
#include<string.h>

int NoofHoles(char *str, int i){
int j=0;
while(str[j]!=’\0’){
str[j]=toupper(str[j]);
if(str[j]==‘A’||str[j]==‘D’|| str[j]==‘O’||str[j]==‘P’||str[j]==‘R’)
i++;
else if(str[j]==‘B’||str[j]==‘Q’)
i+=2;
j++;
}
return i;
}

int main()
{
int t,i=0;
char str=NULL;
fflush(stdin);
scanf("%d",&t);
while(t>0){
i=0;
str=(char
)malloc(sizeof(char)*99);
scanf("%s",str);
i=NoofHoles(str,i);
printf("%d\n",i);
free(str);
t–;
}
return 0;
}

Plz help asap :It gives WA on compiling.

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

still with the same code run time error is comming…
https://www.codechef.com/viewsolution/9491534

for the same code there is error

Nop! It is working correctly! :\ What are you talking about? And another thing. Take char s[101].

ok check
https://www.codechef.com/viewsolution/9491673
this link…

yes,thanx a lot answer came with s[101].
can u explain the reason of using s[101]. :slight_smile:

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.

thanx for your help…
as i have successfully compiled my first program on codechef.