HOLES - Editorial

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.

1 Like

@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

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

}

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

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

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

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 ?

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

#include
#include

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.

#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

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

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

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

#include
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!

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

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

its workin for all test cases.