494 - Kindergarten Counting Game

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

m2lajoo
New poster
Posts: 11
Joined: Thu Jan 11, 2007 9:21 am
Location: iran

Post by m2lajoo » Mon May 07, 2007 8:46 am

this is my AC code try to understand before sending it.

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Where is the bug ?

Post by ranacse05 » Thu Jul 26, 2007 10:15 pm

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;
}
I like to solve problems.

chaitanya
New poster
Posts: 1
Joined: Tue Sep 11, 2007 8:46 pm

494 W.A

Post by chaitanya » Tue Sep 11, 2007 9:05 pm

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

i've gone through all the posts regardin 494 and tested all the cases in this forum. The above code is not getting accepted pls help

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

where's the worng?

Post by apurba » Fri Nov 30, 2007 4:07 pm

i am not finding where's the wrong. help me pls.
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;
}

thank you.

Code: Select all

keep dreaming...

User avatar
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio » Fri Nov 30, 2007 4:38 pm

A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).
Read the statement carefully.

Try this:
Input:

Code: Select all

This!has,four.words?
how about & % $ # ?
Output:

Code: Select all

4
2
-----
Rio[/quote]

ligregni
New poster
Posts: 11
Joined: Thu Nov 29, 2007 12:41 am
Location: Queretaro, M
Contact:

ADVICES!

Post by ligregni » Wed Dec 26, 2007 6:48 am

make you sure that your program recognizes words that doesn't have a !,.,? after like a word
Example:

Input:

Code: Select all

asd...asd
a

hi mate!
the line in blank is intentionally

Output:

Code: Select all

2
1
2
if a line has NO words, don't print ANYTHING (I was getting WA because of that)
I hope it helps!

Sergio Ligregni, MEX.
C: multum in parvo

"a lot since quite few"

http://acmicpc-live-archive.uva.es/nuev ... user=12539

Tarif
New poster
Posts: 3
Joined: Wed Mar 26, 2008 6:44 am
Location: Bangladesh
Contact:

Re: 494 WA

Post by Tarif » Wed May 21, 2008 12:51 pm

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
Tarif Ezaz
Undergraduate student
North South University
12 Kamal Ataturk Avenue, Dhaka

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re:This Can be a Sollution

Post by Obaida » Thu May 22, 2008 1:12 pm

Well I think there's something wrong with this.
In ligregnis input cases My Accepted returns the following output,
Input:

Code: Select all

asd...asd
a

hi mate!
Output:

Code: Select all

2
0
0
2
So who are getting WA can try this input. This could help you to get Accepted! :wink:
try_try_try_try_&&&_try@try.com
This may be the address of success.

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: 494 WA

Post by pok » Thu Dec 11, 2008 9:30 pm

why i got WA evry time?
i cant find any mistake in this code..
so why WA ?

Code: Select all

removed after AC..
pls help me..
Last edited by pok on Sun Dec 14, 2008 10:17 pm, edited 1 time in total.

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 494 WA

Post by Articuno » Sun Dec 14, 2008 12:38 am

Try these cases:

Code: Select all

i
    i am
The output should be:

Code: Select all

1
2
You also forgot about "return 0;" at the end of your main().
Wish you good luck :)
May be tomorrow is a better day............ :)

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: 494 WA

Post by pok » Sun Dec 14, 2008 10:14 pm

thanks Articuno..
now my code is AC..
but for
input:

Code: Select all

a
output:

Code: Select all

0
btw thanks..
take care..
GOD bless you..

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 494 WA

Post by Articuno » Mon Dec 15, 2008 7:32 am

Well, my AC code gives 1 for your input.
As example,In this input:

Code: Select all

He is a boy.
I am a student.
You are considering 'a' and 'I' as a word. So what's wrong with this?

Code: Select all

input:
a
I
output:
1
1
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.
May be tomorrow is a better day............ :)

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

Re: 494 WA

Post by pok » Wed Dec 17, 2008 10:44 pm

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

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Re: 494 WA

Post by newton » Thu Apr 02, 2009 4:54 pm

Though i got accepted earlier the problem 494. but i submit today and got WA.
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;
}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 494 WA

Post by mf » Thu Apr 02, 2009 5:33 pm

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

Post Reply

Return to “Volume 4 (400-499)”