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

tanvirfromhell
New poster
Posts: 5
Joined: Sat Apr 16, 2011 7:42 pm

why WA in 494?!!

Post by tanvirfromhell »

//why I got WA for this code?!!! plz help me.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int count=0;
char a[1000000];
char *p;
while(gets(a))
{
count=0;
p=strtok(a," !.");
while(p!=NULL)
{
p=strtok(NULL," !.");
count++;
}
printf("%d\n",count);
}
return 0;
}

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: why WA in 494?!!

Post by sohel »

Use the search option located at the top right corner to find existing discussions.
Don't create a new thread for a problem that already exists! Make your post on an existing thread.

plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: why WA in 494?!!

Post by plamplam »

I don't see any problem with your code....except for the part p=strtok(NULL," !.");....I don't have the test cases but don't you think its possible to give more punctuations like ' or ( ) or & or @ or ?. So just find a way to exclude every possible punctuations and stuff. Hint : Just include all the upper-case and lower-case chars then every other chars are automatically eliminated. Good luck
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

bristy1588
New poster
Posts: 2
Joined: Sun Jan 29, 2012 12:09 pm

Re: why WA in 494?!!

Post by bristy1588 »

If there is something like mom's. is it a word?

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: why WA in 494?!!

Post by sohel »

mom's has two words - mom and s.

sibhas
New poster
Posts: 1
Joined: Sun Mar 25, 2012 9:37 pm

Re: 494 WA

Post by sibhas »

The following is my code. It is not getting accepted. I do not know why. I have tried all the test cases and they seem to work fine.

The test cases are
salim1233sazzad

abc abc abc





a

Meep Meep!
I tot I taw a putty tat
I did! I did! I did taw a putty tat ....
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ....
I tot I taw a putty tat
I did I did I did taw a putty tat
Shsssssssssh I am hunting wabbits Heh Heh Heh Heh

ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz

#include <iostream>
#include <ostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{
//freopen("input","r",stdin);
string line;
while(getline(cin,line))
{
int count=0;
if(line.length()>0)
{
int j=0;
while(j<line.length())
{

if ((line[j] >='A' && line[j] <='Z') || (line[j] >='a' && line[j] <='z'))
{
count++;
while ((line[j] >='A' && line[j] <='Z') || (line[j] >='a' && line[j] <='z'))
{

j++;
}
}
else
{
while (!((line[j] >='A' && line[j] <='Z') || (line[j] >='a' && line[j] <='z')))
{
j++;
}
}


}
cout << count << endl;
}

}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 494 WA

Post by brianfry713 »

For the sample input, this line is causing a seg fault. You need to check that j<line.length().
while (!((line[j] >='A' && line[j] <='Z') || (line[j] >='a' && line[j] <='z')))
j++
Check input and AC output for thousands of problems on uDebug!

diegon
New poster
Posts: 3
Joined: Fri Jun 08, 2012 10:45 pm

494 WA - Help Needed

Post by diegon »

WA: I don't understand what's the problem. :(
I have checked all the inputs in this topic. Any ideas?

Code: Select all

Thanks brianfry713! Got AC
Last edited by diegon on Wed Jun 13, 2012 5:51 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 494 WA

Post by brianfry713 »

Input:
,a

AC output:
1
Check input and AC output for thousands of problems on uDebug!

PromeNabid
New poster
Posts: 21
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.
Contact:

Re: 494 WA

Post by PromeNabid »

My Ac code gives this output...
Input:

Code: Select all

,a
a
The test cases are
salim1233sazzad
abc abc abc
Meep Meep!
I tot I taw a putty tat
I did! I did! I did taw a putty tat ....
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ....
I tot I taw a putty tat
I did I did I did taw a putty tat
Shsssssssssh I am hunting wabbits Heh Heh Heh Heh
ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
Output:

Code: Select all

1
1
4
2
3
2
7
10
9
7
10
9
2

darksk4
New poster
Posts: 13
Joined: Sun Jul 29, 2012 7:10 pm

Re: 494 WA

Post by darksk4 »

Code: Select all

Thanks brianfry713

I dont know why its WA.... hmmmm its maybe my algorithm
Last edited by darksk4 on Sun Aug 05, 2012 8:15 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 494 WA

Post by brianfry713 »

If counter is zero you shouldn't try to read w[counter - 1]
Check input and AC output for thousands of problems on uDebug!

shuvrothpol1
New poster
Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

Re: 494 WA

Post by shuvrothpol1 »

Can anyone help to find out my problem. My code gives the correct answer but i get wa.The code iven below:
#include <stdio.h>
#include <string.h>

int main ()

{
char str[999999];
int i,count;

while (gets (str)){
count=0;
for (i=0;str!='\0';i++)
{if (str==' '&&((str[i+1]>=65&&str[i+1]<=90)||str[i+1]>=97&&str[i+1]<=122))
count++;
else if((str>=33&&str<=64)||(str>=91&&str<=96)||(str>=123&&str<=126))
str[i--]=' ';
}
printf ("%d\n",++count);
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 494 WA

Post by brianfry713 »

Try input

Code: Select all

,a
Check input and AC output for thousands of problems on uDebug!

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh
Contact:

Re: 494 WA

Post by alimbubt »

Some Critical Input That harasses me....
Input:

Code: Select all

,,alim
@@alim0123alim%%alim.
..alim222.. .. .. &&alim
Bangladesh University of Business & Technology
(Alim)(Alim)(Alim)
(Alim) (Alim)()
Output:

Code: Select all

1
3
2
5
3
2
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

Post Reply

Return to “Volume 4 (400-499)”