494 - Kindergarten Counting Game
Moderator: Board moderators
Getting wrong answer on 494
I have tried all thing. All creatical input and output set. The answer was correct. But I am getting wrong answer. My code is
#include<iostream>
using namespace std;
int main()
{
//freopen("1.txt","r",stdin);
char c;
int count=0,space=1;
while((c=getchar())!=EOF)
{
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
{
if(space)
{
count++;
space=0;
}
}
else if(c=='\n'||c=='\r')
{
cout<<count<<endl;
count=0;
space=1;
}
else
space=1;
}
cout<<count<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
//freopen("1.txt","r",stdin);
char c;
int count=0,space=1;
while((c=getchar())!=EOF)
{
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
{
if(space)
{
count++;
space=0;
}
}
else if(c=='\n'||c=='\r')
{
cout<<count<<endl;
count=0;
space=1;
}
else
space=1;
}
cout<<count<<endl;
return 0;
}
Re: Getting wrong answer on 494
* Don't post duplicate messages
* Don't start a new thread, do search for an existing thread on problem 494 and post there.
* Read existing replies in that thread before posting.
* Use [code]...[/code] tags to format source code.
* And in case if you need to start a new thread for a problem, which wasn't yet discussed, follow the convention for thread's title: "<Problem's number> - <Problem's title>". No "Gettign W/A on problem" or anything like that.
* Don't start a new thread, do search for an existing thread on problem 494 and post there.
* Read existing replies in that thread before posting.
* Use [code]...[/code] tags to format source code.
* And in case if you need to start a new thread for a problem, which wasn't yet discussed, follow the convention for thread's title: "<Problem's number> - <Problem's title>". No "Gettign W/A on problem" or anything like that.
Re: 494 Kinder Garden Counting Game WA
If there is two new line what should the program out put 0 or nothing.
-
- New poster
- Posts: 5
- Joined: Wed Sep 23, 2009 8:57 am
Re: 494 WA
getting Wa
can anyone help please?
can anyone help please?
Code: Select all
#include<stdio.h>
#include<string.h>
int main(){
unsigned long int a,b,d,x,y,z,l;
char c,m[50000];
while(gets(m)){
l=strlen(m);
b=0;
for(a=0;a<l;a++){
c=m[a];
if(((c<65)||(c>122))||((c>90)&&(c<97)))
continue;
while(((m[a]>65)&&(m[a]<91))||((m[a]>96)&&(m[a]<123))){
if(m[a]==10)
break;
a++;
}
b++;
}
printf("%lu\n",b);
}
return 0;
}
Re: 494 WA
Every Body who have faced W/A in this problem use isalpha function.
It will be lot easier for you.
It will be lot easier for you.
Re: 494 WA
code removed ....
Last edited by mehrab on Tue Jul 13, 2010 1:05 pm, edited 1 time in total.
Re: 494 WA
1.should the program print 0 for only one letter input?
2.should i print blank line for a blank input or should i print 0?
thnx
2.should i print blank line for a blank input or should i print 0?
thnx
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 494 WA
Did yo notice that ->
But if you still want to know what is the output of one letter input then i can say my ACC program return 1 for one letter
input.
And your second question is already answered(At least one word in input,no blank line in input).
This means that there is no one letter input(Bcoz it is not a word, A word is defined as a consecutive sequence of letters,And each line containing multiple words (at least one).)each line containing multiple words (at least one). A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).
But if you still want to know what is the output of one letter input then i can say my ACC program return 1 for one letter
input.
And your second question is already answered(At least one word in input,no blank line in input).
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 494 WA
thnx for da reply ...
but hav u seen my code ... what's wrong there why my code is getting WA
but hav u seen my code ... what's wrong there why my code is getting WA
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 494 WA
I think ur tab character does not work correctly.For input
ab<tab>cd<tab>ef
your output produce 1 ,which should be 3.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 494 WA
i'm using visual c++ compiler and it is producing correct answer for your input...
does it cause any problem for using two different compilers??
does it cause any problem for using two different compilers??
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 494 WA
I am also using visual c++ compiler , But in my compiler
And your code is no longer in board.So i cant test it again.ab<tab>cd<tab>ef
your output produce 1 ,which should be 3.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
494 test my code. why WA?
why wrong answer? please help me
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define M 1000000
int main()
{
//freopen ("494.txt","r",stdin);
char text[M],*t;
int f,i,count,tem;
while(gets(text))
{
count=0;
t=strtok(text," !.,;~!@#$%^&*()\t_\?/\n");
while(t)
{
f=0;
tem=strlen(t);
for(i=0;i<tem;i++)
if(t[i]>='A'&&t[i]<='Z'||t[i]>='a'&&t[i]<='z')
{
f=1;
break;
}
if(f)
count++;
t=strtok(NULL," !.,;~!@#$%^&*()\t_\?/\n");
}
printf("%d\n",count);
}
return 0;
}
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 494 WA
Ok,tell me what will be the output of
your code produce 1.And the correct answer is 2.
Code: Select all
salim1233sazzad
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 494 WA
Thanks for your reply , i got AC
![]()