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

×

HOLES - Editorial

1
2

PROBLEM LINKS

Practice
Contest

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

admin's gravatar image

0★admin ♦♦
19.8k350498541
accept rate: 36%

include<iostream>

using namespace std;

int main() { char str[100];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) senginel2★

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

include<stdio.h>

include<string.h>

int main() { int i,j,k,holes; char a , word[20]; 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) anoopgupta1662★

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

(07 Nov '13, 22:37) VincentVega2★

include<iostream>

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 ?

(17 Dec '13, 22:13) pardeep_gill2★

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

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

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.

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

@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
link

answered 26 Jul '13, 15:07

nitish1402's gravatar image

3★nitish1402
31115
accept rate: 0%

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


int main()
{
      int i,j=0,t,count1,count2;
      char a[100];


      scanf("%d",&t);

      while(j<t)
      {
      if(t<=40)
      {
            scanf("%s",&a);
               count1=0;
               count2=0;
            for(i=0;a[i]!='\0';i++)
            {

                   if(a[i]=='A'||a[i]=='D'||a[i]=='O'||a[i]=='P'||a[i]=='Q'||a[i]=='R')
                       count1++;



                    else if(a[i]=='B')
                        count2=count2+2;



                           }


                           printf("%d",count1+count2);
      }
                           j++;


                           }

                           return 0;

}
link

answered 07 Nov '13, 15:35

sun1sun8080's gravatar image

2★sun1sun8080
1
accept rate: 0%

edited 08 Nov '13, 09:52

kunal361's gravatar image

4★kunal361
6.0k133272

What's wrong in this?/ why it is not accepting

its workin for all test cases.

(07 Nov '13, 15:37) sun1sun80802★

@sun1sun8080 i think u r not printing a new-line after every case...mostly that is the reason for your WA...hope this helps...:)

link

answered 08 Nov '13, 09:54

kunal361's gravatar image

4★kunal361
6.0k133272
accept rate: 21%

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

link

answered 16 May '14, 17:07

reversiblean's gravatar image

2★reversiblean
1113
accept rate: 0%

edited 16 May '14, 17:09

Those are just examples.

(16 May '14, 17:11) wittyceaser2★

whats wrong with this code

 #include <stdio.h>
    #include <string>
    #include <iostream>
    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;
    }
link

answered 06 Jun '14, 01:02

the_run's gravatar image

2★the_run
1624
accept rate: 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 ?

link

answered 08 Aug '14, 00:23

aruna2014's gravatar image

0★aruna2014
1
accept rate: 0%

include<stdio.h>

include<malloc.h>

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.

link

answered 08 Aug '14, 03:16

s1r5_3's gravatar image

0★s1r5_3
1
accept rate: 0%

include<iostream>

include<cstdio>

using namespace std;

int main() { int test; cin >> test; while(test--) { int count=0,i=0; char str[110]; 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.

link

answered 22 Mar '15, 09:47

sravin96's gravatar image

0★sravin96
1
accept rate: 0%

include<stdio.h>

include<stdlib.h>

int main() { int t; scanf("%d",&t); char a[100]; 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

link
This answer is marked "community wiki".

answered 14 May '15, 17:58

dexteridea22's gravatar image

2★dexteridea22
1
accept rate: 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

link

answered 16 May '15, 20:48

mallika13055's gravatar image

2★mallika13055
1
accept rate: 0%

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
link

answered 16 Dec '15, 23:27

catseye143's gravatar image

0★catseye143
1
accept rate: 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

link

answered 20 Jan '16, 10:47

anmol591's gravatar image

0★anmol591
1
accept rate: 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

???

link

answered 28 Jan '16, 00:17

ashusingla's gravatar image

1★ashusingla
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

link

answered 26 Feb '16, 22:51

nanhe's gravatar image

3★nanhe
413
accept rate: 0%

include<iostream>

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

link

answered 26 Feb '16, 22:52

nanhe's gravatar image

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) debjitdj4★

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

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

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

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

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

(27 Feb '16, 00:07) debjitdj4★
(27 Feb '16, 00:12) nanhe3★

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

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

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) debjitdj4★

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

(27 Feb '16, 00:29) nanhe3★
showing 5 of 8 show all
link

answered 27 Feb '16, 00:10

nanhe's gravatar image

3★nanhe
413
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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