Could someone please help me out with this? I’m getting WA with this code, but I’m unable to spot the bug.
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;
}
- 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
#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.
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;
}
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 ?
@pradeep_gill post link to your submission, the above format is unreadable.
Those are just examples.
#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.
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 Nhgdqs - Online C++0x Compiler & Debugging Tool - Ideone.com
for the same code there is error
Nop! It is working correctly! :\ What are you talking about? And another thing. Take char s[101].