Page 7 of 8

why WA in 494?!!

Posted: Thu Apr 28, 2011 11:32 am
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;
}

Re: why WA in 494?!!

Posted: Fri Apr 29, 2011 12:44 am
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.

Re: why WA in 494?!!

Posted: Wed May 25, 2011 6:18 pm
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

Re: why WA in 494?!!

Posted: Mon Jan 30, 2012 12:03 pm
by bristy1588
If there is something like mom's. is it a word?

Re: why WA in 494?!!

Posted: Mon Jan 30, 2012 10:18 pm
by sohel
mom's has two words - mom and s.

Re: 494 WA

Posted: Sun Mar 25, 2012 10:03 pm
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;
}

Re: 494 WA

Posted: Tue Mar 27, 2012 11:50 pm
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++

494 WA - Help Needed

Posted: Fri Jun 08, 2012 10:59 pm
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

Re: 494 WA

Posted: Mon Jun 11, 2012 11:39 pm
by brianfry713
Input:
,a

AC output:
1

Re: 494 WA

Posted: Mon Jun 18, 2012 1:02 am
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

Re: 494 WA

Posted: Fri Aug 03, 2012 6:39 am
by darksk4

Code: Select all

Thanks brianfry713

I dont know why its WA.... hmmmm its maybe my algorithm

Re: 494 WA

Posted: Fri Aug 03, 2012 11:39 pm
by brianfry713
If counter is zero you shouldn't try to read w[counter - 1]

Re: 494 WA

Posted: Wed Sep 12, 2012 1:29 pm
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;
}

Re: 494 WA

Posted: Wed Sep 12, 2012 8:59 pm
by brianfry713
Try input

Code: Select all

,a

Re: 494 WA

Posted: Fri Feb 15, 2013 2:07 pm
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