494 - Kindergarten Counting Game
Moderator: Board moderators
Where is the bug ?
Can any body help me? Why i got WA again and again?
#include<stdio.h>
#include<string.h>
int word(char a[],int i)
{
int j;
for(j=0;j<i;j++)
if((a[j]>='a' && a[j]<='z') || (a[j]>='A' && a[j]<='Z') || (a[j]>='0' && a[j]<='9' ))
return 1;
return 0;
}
int main()
{
char a[800],b[800];
int i,j,k,ln;
while(gets(a))
{
i=0;k=0;j=0;
ln=strlen(a);
while(a!='\0')
{
b[j++]=a;
if(a==' ' || i==ln-1)
{
b[j]='\0';
if(word(b,j))
k++;
j=0;
}
i++;
}
printf("%d\n",k);
}
return 0;
}
#include<stdio.h>
#include<string.h>
int word(char a[],int i)
{
int j;
for(j=0;j<i;j++)
if((a[j]>='a' && a[j]<='z') || (a[j]>='A' && a[j]<='Z') || (a[j]>='0' && a[j]<='9' ))
return 1;
return 0;
}
int main()
{
char a[800],b[800];
int i,j,k,ln;
while(gets(a))
{
i=0;k=0;j=0;
ln=strlen(a);
while(a!='\0')
{
b[j++]=a;
if(a==' ' || i==ln-1)
{
b[j]='\0';
if(word(b,j))
k++;
j=0;
}
i++;
}
printf("%d\n",k);
}
return 0;
}
I like to solve problems.
494 W.A
Code: Select all
/*494*/
#include<stdio.h>
int main()
{
char ch;
int count = 0;
char space = 1;
while((ch = getchar()) != EOF) {
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
if(space) {
count++;
space = 0;
}
}else if(ch == '\n' || ch == '\r') {
printf("%d\n", count);
count = 0;
space = 1;
}else {
space = 1;
}
}
printf("%d", count);
return 0;
}
where's the worng?
i am not finding where's the wrong. help me pls.
here is my code...........
thank you.
here is my code...........
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char s[1001];
char temp[1001];
long len;
long i,t,x;
long count;
int main()
{
while(gets(s))
{
len=strlen(s);
t=0;
for(i=0;i<len;i++)
{
//t=0;
if(s[i]!='.'||s[i]!=','||s[i]!='!'||s[i]!='?')
{
temp[t]=s[i];
t++;
}
}
count=1;
for(x=0;x<t;x++)
{
if(temp[x]==' ')
count++;
else if(temp[x]==' ' && temp[x-1]==' ')
count--;
}
printf("%ld\n",count);
}
return 0;
}
Code: Select all
keep dreaming...
Read the statement carefully.A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).
Try this:
Input:
Code: Select all
This!has,four.words?
how about & % $ # ?
Code: Select all
4
2
Rio[/quote]
ADVICES!
Example:make you sure that your program recognizes words that doesn't have a !,.,? after like a word
Input:
Code: Select all
asd...asd
a
hi mate!
Output:
Code: Select all
2
1
2
I hope it helps!if a line has NO words, don't print ANYTHING (I was getting WA because of that)
Sergio Ligregni, MEX.
Re: 494 WA
I guess my algorithm is ok and it's showing the right result for all the test cases above. But I want to know exactly how long a line can be. If it's too long, then I should not depend upon arrays and follow some other approach! Please let me know!
Regards...
Tarif
Regards...
Tarif
Tarif Ezaz
Undergraduate student
North South University
12 Kamal Ataturk Avenue, Dhaka
Undergraduate student
North South University
12 Kamal Ataturk Avenue, Dhaka
Re:This Can be a Sollution
Well I think there's something wrong with this.
In ligregnis input cases My Accepted returns the following output,
Input:
Output:
So who are getting WA can try this input. This could help you to get Accepted! 
In ligregnis input cases My Accepted returns the following output,
Input:
Code: Select all
asd...asd
a
hi mate!
Code: Select all
2
0
0
2

try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 494 WA
why i got WA evry time?
i cant find any mistake in this code..
so why WA ?
pls help me..
i cant find any mistake in this code..
so why WA ?
Code: Select all
removed after AC..
Last edited by pok on Sun Dec 14, 2008 10:17 pm, edited 1 time in total.
-
- Learning poster
- Posts: 78
- Joined: Sun Nov 30, 2008 5:00 pm
- Location: IUT-OIC, Dhaka, Bangladesh
Re: 494 WA
Try these cases:
The output should be:
You also forgot about "return 0;" at the end of your main().
Wish you good luck
Code: Select all
i
i am
Code: Select all
1
2
Wish you good luck

May be tomorrow is a better day............ 

Re: 494 WA
thanks Articuno..
now my code is AC..
but for
input:
output:
btw thanks..
take care..
GOD bless you..
now my code is AC..
but for
input:
Code: Select all
a
Code: Select all
0
take care..
GOD bless you..
-
- Learning poster
- Posts: 78
- Joined: Sun Nov 30, 2008 5:00 pm
- Location: IUT-OIC, Dhaka, Bangladesh
Re: 494 WA
Well, my AC code gives 1 for your input.
As example,In this input:
You are considering 'a' and 'I' as a word. So what's wrong with this?
Why the output should be 0?
I dont understand.
I think the judge data has no such input that's why both of our codes are AC.
As example,In this input:
Code: Select all
He is a boy.
I am a student.
Code: Select all
input:
a
I
output:
1
1
I dont understand.
I think the judge data has no such input that's why both of our codes are AC.
May be tomorrow is a better day............ 

Re: 494 WA
i think u r right Articuno..
there is no input like that..
but in uvatoolkit it gives 0 for that input..
that why i made my code like that..
take care..
God bless u..
there is no input like that..
but in uvatoolkit it gives 0 for that input..
that why i made my code like that..
take care..
God bless u..
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
Re: 494 WA
Though i got accepted earlier the problem 494. but i submit today and got WA.
Why please check my code.
Why please check my code.
Code: Select all
#include <cstdio>
#include <cstring>
#define MAX 1000
int main(){
//freopen("in.txt","rt",stdin);
char str[MAX],*p;
int c;
while(gets(str)){
c = 0;
p = strtok(str," !.,;~!@#$%^&*()\t_\?/\n");
while(p){
c++;
p = strtok(NULL," !.,;~!@#$%^&*()\t_\?/\n");
}
if(c)
printf("%d\n",c);
}
return 0;
}
Re: 494 WA
You got WA because your program doesn't do what it's asked to do! Duh.
Read the problem again - it defines a word as a maximal sequence of consecutive letters.
But your program thinks a word is anything that doesn't contain any of "!.,;~!@#$%^&*()\t_\?/\n".
These two definitions of 'word' don't look identical to me at all.
You would need to include all the 255-2*26 ASCII characters in your search string to make them equal; but there's of course a better way to solve this (hint: isalpha() function).
Read the problem again - it defines a word as a maximal sequence of consecutive letters.
But your program thinks a word is anything that doesn't contain any of "!.,;~!@#$%^&*()\t_\?/\n".
These two definitions of 'word' don't look identical to me at all.
You would need to include all the 255-2*26 ASCII characters in your search string to make them equal; but there's of course a better way to solve this (hint: isalpha() function).