494 - Kindergarten Counting Game
Moderator: Board moderators
-
- New poster
- Posts: 5
- Joined: Sat Apr 16, 2011 7:42 pm
why WA in 494?!!
//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;
}
#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;
}
Re: why WA in 494?!!
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.
Don't create a new thread for a problem that already exists! Make your post on an existing thread.
Re: why WA in 494?!!
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
-
- New poster
- Posts: 2
- Joined: Sun Jan 29, 2012 12:09 pm
Re: why WA in 494?!!
If there is something like mom's. is it a word?
Re: 494 WA
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;
}
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 494 WA
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++
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!
494 WA - Help Needed
WA: I don't understand what's the problem. 
I have checked all the inputs in this topic. Any ideas?

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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
-
- New poster
- Posts: 21
- Joined: Mon Jun 18, 2012 12:52 am
- Location: Dhaka, Bangladesh.
- Contact:
Re: 494 WA
My Ac code gives this output...
Input:
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
Code: Select all
1
1
4
2
3
2
7
10
9
7
10
9
2
Re: 494 WA
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 494 WA
If counter is zero you shouldn't try to read w[counter - 1]
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 17
- Joined: Wed Aug 15, 2012 12:37 pm
Re: 494 WA
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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 494 WA
Try input
Code: Select all
,a
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 39
- Joined: Tue Aug 07, 2012 10:40 pm
- Location: BUBT,Dhaka, Bangladesh
- Contact:
Re: 494 WA
Some Critical Input That harasses me....
Input:
Output:
Input:
Code: Select all
,,alim
@@alim0123alim%%alim.
..alim222.. .. .. &&alim
Bangladesh University of Business & Technology
(Alim)(Alim)(Alim)
(Alim) (Alim)()
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/
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/