Can any one check my code pls. Why I am gettting wrong answer?
#include<stdio.h>
void main(void)
{
int ch,c,start_s,start_w;
c=0;
start_s=1,start_w=0;
while((ch=getchar())!=-1)
{
if(ch=='\n')continue;
if(ch=='.' || ch=='?' || ch=='!')
{start_s=1;continue;}
if(ch==' '){start_w=1;continue;}
if(start_s && ch>='a' && ch<='z')
{start_s=start_w=0;c++;continue;}
else
{
if(!start_s && start_w && ch>='A' && ch<='Z')
c++;
start_w=0;
start_s=0;
}
}
printf("%d\n",c);
}
Re:
Well, when you encounter a line break you should change
start_w to 0 as a line break is a word separator.
Good luck.
Re:
Thanks to Ivan Georgiev
But still I am getting WA.
Would you check it again.
Here the modified code
#include<stdio.h>
void main(void)
{
int ch,c,start_s,start_w;
freopen("D:\\1038.in","rt",stdin);
c=0;
start_s=1,start_w=0;
while((ch=getchar())!=-1)
{
if(ch=='\n'){start_s=1,start_w=0;continue;}
if(ch=='.' || ch=='?' || ch=='!')
{start_s=1;continue;}
if(ch==' ')
{start_w=1;continue;}
if(start_s && ch>='a' && ch<='z')
{start_s=start_w=0;c++;continue;}
else
{
if(!start_s && start_w && ch>='A' && ch<='Z')
c++;
start_w=0;start_s=0;
}
}
printf("%d\n",c);
}
Re: Still WA
> Thanks to Ivan Georgiev
> But still I am getting WA.
> Would you check it again.
>
> Here the modified code
>
> #include<stdio.h>
>
> void main(void)
> {
> int ch,c,start_s,start_w;
> freopen("D:\\1038.in","rt",stdin);
>
> c=0;
> start_s=1,start_w=0;
> while((ch=getchar())!=-1)
> {
> if(ch=='\n'){start_s=1,start_w=0;continue;}
> if(ch=='.' || ch=='?' || ch=='!')
> {start_s=1;continue;}
> if(ch==' ')
> {start_w=1;continue;}
> if(start_s && ch>='a' && ch<='z')
> {start_s=start_w=0;c++;continue;}
> else
> {
> if(!start_s && start_w && ch>='A' && ch<='Z')
> c++;
> start_w=0;start_s=0;
> }
> }
> printf("%d\n",c);
> }
>
Re:
> Thanks to Ivan Georgiev
> But still I am getting WA.
> Would you check it again.
>
> Here the modified code
>
> #include<stdio.h>
>
> void main(void)
> {
> int ch,c,start_s,start_w;
> freopen("D:\\1038.in","rt",stdin);
>
> c=0;
> start_s=1,start_w=0;
> while((ch=getchar())!=-1)
> {
> if(ch=='\n'){start_s=1,start_w=0;continue;}
> if(ch=='.' || ch=='?' || ch=='!')
> {start_s=1;continue;}
> if(ch==' ')
> {start_w=1;continue;}
> if(start_s && ch>='a' && ch<='z')
> {start_s=start_w=0;c++;continue;}
> else
> {
> if(!start_s && start_w && ch>='A' && ch<='Z')
> c++;
> start_w=0;start_s=0;
> }
> }
> printf("%d\n",c);
> }
>
Words can be separated by more than one space (and other
characters as well). I think that's the problem.
Re:
> Thanks to Ivan Georgiev
> But still I am getting WA.
> Would you check it again.
>
> Here the modified code
>
> #include<stdio.h>
>
> void main(void)
> {
> int ch,c,start_s,start_w;
> freopen("D:\\1038.in","rt",stdin);
>
> c=0;
> start_s=1,start_w=0;
> while((ch=getchar())!=-1)
> {
> if(ch=='\n'){start_s=1,start_w=0;continue;}
> if(ch=='.' || ch=='?' || ch=='!')
> {start_s=1;continue;}
> if(ch==' ')
> {start_w=1;continue;}
> if(start_s && ch>='a' && ch<='z')
> {start_s=start_w=0;c++;continue;}
> else
> {
> if(!start_s && start_w && ch>='A' && ch<='Z')
> c++;
> start_w=0;start_s=0;
> }
> }
> printf("%d\n",c);
> }
>
Words can be separated by more than one space (and other
characters as well). I think that's the problem.
Re: Can you give any judge data for which this code gives WA.
> > Thanks to Ivan Georgiev
Can you give any judge data for that it gives WA.
I think that will be good for me to judge.
Re: Can you give any judge data for which this code gives WA.
> > > Thanks to Ivan Georgiev
>
> Can you give any judge data for that it gives WA.
> I think that will be good for me to judge.
Try this tests:
The old vaRsag my
Antonesgh..%sg4mahng 35tsavx
3mnkxb o o oo AA gfsd . sdgw a
aA
Aa
The answer is 5
I am good and evil.
i $JHBFS# dreams dreA
MS and DREAMS.222
The answer is 12
Re: What about any symbols?
I think that you cann't use symbols:'@','#','$','%','&'...
Re: What about any symbols?
Posted by
TNTeam 18 Mar 2006 00:56
Input contains a text that consists of capital and small letters of the Latin alphabet (A–Z, a–z), punctuation marks (.,;:-!?) and spaces.
Re: Can you give any judge data for which this code gives WA.
Thank you very much.I think I can accept it now.
Re: Can you give any judge data for which this code gives WA.
Posted by
Rafal 6 Jun 2007 13:07
> Try this tests:
>
> The old vaRsag my
> Antonesgh..%sg4mahng 35tsavx
> 3mnkxb o o oo AA gfsd . sdgw a
> aA
> Aa
My AC code returns 4.
Edited by author 06.06.2007 13:07
Re: Can you give any judge data for which this code gives WA.
Posted by
SHMAK 5 Nov 2007 05:17
strange... but there are 5 mistakes:
The old va[R]sag my
Antonesgh..%[s]g4mahng 35tsavx
3mnkxb o o oo A[A] gfsd . [s]dgw a
a[A]
Aa