You are not logged in. Please login at www.codechef.com to post your questions!

×

# DIFFICULTY

EASY

EXPLANATION You just simply need to do what is mentioned in problem statement. Just note that only letter “B” has two holes, and only letters “A”, “D”, “O”, “P”, “Q”, “R” have one hole. All other letters has no holes.

# SETTER'S SOLUTION

Can be found here.

# TESTER'S SOLUTION

Can be found here.

This question is marked "community wiki".

asked 27 Nov '12, 12:34 19.8k350498541
accept rate: 36%

# include<iostream>

using namespace std;

int main() { char str;int hole=0; cout<<"Enter word"; cin>>str; for(int i=0;str[i]!='\0';i++) { if(str[i]=='A'||str[i]=='D'||str[i]=='O'||str[i]=='P'||str[i]=='R') hole++; else if(str[i]=='B') hole+=2; } cout<<hole;

return 0; }

The following code returns a wrong answer error! Its working fine on my compiler. Please help!

(26 Jul '13, 14:17) 2★

Can anyone told me why runtime error occur in this code(according to submission)

# include<string.h>

int main() { int i,j,k,holes; char a , word; scanf("%d",&i); for(j=0;j<i;j++) { scanf("%s",word); holes=0; for(k=0;k<strlen(word-1);k++) { a=word[k]; if(a=='A'||a=='D'||a=='O'||a=='P'||a=='Q'||a=='R') holes+=1; if(a=='B') holes+=2; } printf("\nHOLES ARE %d\n",holes); } return 0; }

(15 Oct '13, 16:05)

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<iostream>

using namespace std; int b,t,i,c; char d; int holes(char a) { 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; }

(07 Nov '13, 22:37)

# include<iostream>

using namespace std;

int main() { int t,i=0; char text; 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 ?

(17 Dec '13, 22:13)

(17 Dec '13, 23:01) 3★
(18 Dec '13, 21:57)

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

(08 Aug '14, 03:15) 0★
showing 5 of 7 show all

 0 @senginel you are asking for input in cout<<"enter Word " which is not required further more you have to input test cases which u haven"t done and also increase hole by 1 when str[i]==Q;  look at this code http://www.codechef.com/viewsolution/2404650  answered 26 Jul '13, 15:07 31●1●1●5 accept rate: 0%
 0 #include #include int main() { int i,j=0,t,count1,count2; char a; scanf("%d",&t); while(j
 0 @sun1sun8080 i think u r not printing a new-line after every case...mostly that is the reason for your WA...hope this helps...:) answered 08 Nov '13, 09:54 4★kunal361 6.0k●13●32●72 accept rate: 21%
 0 I've been struggling to find out what's wrong with my code. The problem is the problem itself. "For example letters "A", "D", "O", "P", "R" divide the plane into two regions so we say these letters each have one hole...." .. should be corrected as "A, D, O, P, Q, R" in codechef.com/problems/HOLES answered 16 May '14, 17:07 1●1●1●3 accept rate: 0% Those are just examples. (16 May '14, 17:11)
 0 whats wrong with this code  #include #include #include int main () { using namespace std; int t; int len; scanf("%d\n",&t); while (t>0){ int cnt = 0; string inp; cin >> inp; len = inp.length(); string h = "ADOPR"; for (int i=0; i <=4; i++){ int ff,kk; ff = 0; kk = 0; for (int p = 0; p <= len; p++){ ff = inp.find(h[i],ff); if (ff == -1 && i < 4){ break; } if(i==4) { kk = inp.find("B",kk); if (kk!=-1){ kk = kk + 1; cnt = cnt + 2; } if (ff!=-1){ ff = ff + 1; cnt++; } if (ff == -1 && kk == -1){ break; } } else { ff = ff + 1; cnt++; } } } t--; printf("%d\n",cnt); } return 0; }  answered 06 Jun '14, 01:02 2★the_run 16●2●4 accept rate: 0%
 0 import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner inp = new Scanner(System.in); int tc = inp.nextInt(); int count; while(tc-- > 0) { count = 0; String str = inp.nextLine(); for(int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 'A': case 'D': case 'O': case 'P': case 'R': case 'Q':count++; break; case 'B':count += 2; break; } } System.out.println(count); } inp.close(); }  } What's wrong this code ? answered 08 Aug '14, 00:23 1 accept rate: 0%

# include<string.h>

char toupper(char c){ int i; if(c>=97 || c<=122){ i=c; i-=32; c=(char)i; } return c; }

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]=='Q'||str[j]=='R') i++; else if(str[j]=='B') 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.

answered 08 Aug '14, 03:16 0★s1r5_3
1
accept rate: 0%

# include<cstdio>

using namespace std;

int main() { int test; cin >> test; while(test--) { int count=0,i=0; char str; cin >> str; while(str[i]!='\0') { if(str[i]== 'A' || str[i]== 'D' ||str[i]== 'O' ||str[i]== 'P' ||str[i]== 'R' ||str[i]== 'Q') count++; if(str[i]== 'B') count+=2; i++; } cout << count; } return 0; }

Please help me with my code I am getting Wrong Answer. I am not getting why.

answered 22 Mar '15, 09:47 0★sravin96
1
accept rate: 0%

# include<stdlib.h>

int main() { int t; scanf("%d",&t); char a; int j=1; if(t<=40) {while(j<=t) {
scanf("%s",a); int count1=0; int count2=0; int i=0; while(a[i]!='\0') { if(a[i]=='A'||a[i]=='D'||a[i]=='O'||a[i]=='P'||a[i]=='R') { count=count+1; } else if(a[i]=='B') {

        count=count+2;
}
i++;
}
printf("%d\n",count);
j++;
}

}
return 0;


} WATS WRONG WITH THIS CODE IT SAYS WA BUT IS RUNNING FOR ALL TEST CASE

This answer is marked "community wiki".

answered 14 May '15, 17:58 1
accept rate: 0%

 0 Could someone please help me out with this? I'm getting WA with this code, but I'm unable to spot the bug. https://ideone.com/3fOyjV answered 16 May '15, 20:48 1 accept rate: 0%

could someone tell me my mistake!

# include <stdlib.h>

int main() { int holes,length,test,i; holes = 0; char word; 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

answered 16 Dec '15, 23:27 1
accept rate: 0%

 0 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 answered 20 Jan '16, 10:47 0★anmol591 1 accept rate: 0%
 0 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 ??? answered 28 Jan '16, 00:17 1 accept rate: 0%

# 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

answered 26 Feb '16, 22:51 3★nanhe
413
accept rate: 0%

# include<string.h>

using namespace std; main() { int c=0,n; char s; 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

answered 26 Feb '16, 22:52 3★nanhe
413
accept rate: 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 https://ideone.com/Nhgdqs

(26 Feb '16, 23:29) 4★

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

(26 Feb '16, 23:52) 3★

for the same code there is error https://ideone.com/5E0w0c

(27 Feb '16, 00:01) 3★

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

(27 Feb '16, 00:07) 4★
(27 Feb '16, 00:12) 3★

yes,thanx a lot answer came with s. can u explain the reason of using s. :)

(27 Feb '16, 00:14) 3★

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.

(27 Feb '16, 00:22) 4★

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

(27 Feb '16, 00:29) 3★
showing 5 of 8 show all
 0 code having run time error https://www.codechef.com/viewsolution/9491534 answered 27 Feb '16, 00:10 3★nanhe 41●3 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×3,820
×37
×5

question asked: 27 Nov '12, 12:34

question was seen: 9,189 times

last updated: 27 Feb '16, 00:29