HOLES - Editorial

could someone tell me my mistake!

#include <stdio.h>
#include <stdlib.h>

int main()
{
int holes,length,test,i;
holes = 0;
char word[100];
printf(“please enter the number of test cases\n”);
scanf("%d",&test);
while(test–)
{
scanf("%s",&word);
length = strlen(word);
for(i=0;i<length;i++){
if(word[i]==‘A’ || word[i]==‘D’ || word[i]==‘O’ || word[i]==‘P’ || word[i]==‘Q’ ||word[i]==‘R’ )
{
holes+=1;
}
else if(word[i]==‘B’)
{
holes+=2;
}
}
printf("%d \n",holes);
holes=0;

}
return 0;

}

  1. List item

pls someone help me…i am very beginner in competitive programming.I just want to know what are the test cases for this specific problem

Can someone Please tell whats wrong with this solution, works fine in visual studio for various inputs
https://www.codechef.com/viewsolution/9246206

its similar to the solution given above by @aruna2014.

Input : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Output : 8

???

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,c,i;
string s;
cin>>t;
while(t–)
{
cin>>s;
c=0;
for(i=0;i<s.size();i++)
{
if((s[i]==‘A’)||(s[i]==‘D’)||(s[i]==‘O’)||(s[i]==‘P’)||(s[i]==‘Q’)||(s[i]==‘R’))
c++;
else if(s[i]==‘B’)
c+=2;
}
cout<<c<<endl;
}
}

IS MY CODE GETTING RUNTIME ERROR CAN U SOLVE

#include
#include<string.h>
using namespace std;
main()
{
int c=0,n;
char s[40];
cin>>n;
while(n–)
{
cin>>s;
for(int i=0;i<strlen(s);i++)
{
if( (s[i]==‘A’)||(s[i]==‘D’)||(s[i]==‘P’)||(s[i]==‘Q’)||(s[i]==‘R’)||(s[i]==‘Q’) )
{
c++;
}
else if(s[i]==‘B’)
{
c=c+2;
}
}

  cout<<c;
}

}

IS MY CODE GETTING RUNTIME ERROR CAN U SOLVE

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 https://ideone.com/Nhgdqs

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].

code having run time error
https://www.codechef.com/viewsolution/9491534

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.