admin
November 27, 2012, 12:34pm
1
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
#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!
@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
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;
}
#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;
}
What’s wrong in this?/ why it is not accepting
its workin for all test cases.
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;
}
@sun1sun8080 i think u r not printing a new-line after every case…mostly that is the reason for your WA…hope this helps…
#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 ?
s1h33p
December 17, 2013, 11:01pm
10
@pradeep_gill post link to your submission, the above format is unreadable.
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 ?
s1r5_3
August 8, 2014, 3:15am
16
#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.
s1r5_3
August 8, 2014, 3:16am
17
#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