ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1038. Spell Checker

Can any one check my code pls. Why I am gettting wrong answer?
Posted by Alam Md Mahabub 27 Sep 2001 14:23


#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:
Posted by Ivan Georgiev 27 Sep 2001 14:45
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:
Posted by Alam Md Mahabub 28 Sep 2001 02:42
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
Posted by Alam Md Mahabub 28 Sep 2001 02:43
> 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:
Posted by Ivan Georgiev 28 Sep 2001 04:21
> 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:
Posted by Ivan Georgiev 28 Sep 2001 04:22
> 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.
Posted by Alam Md Mahabub 28 Sep 2001 20:43
> > 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.
Posted by Ivan Georgiev 29 Sep 2001 02:01
> > > 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?
Posted by Book WORMs 17 Apr 2002 17:54
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.
Posted by John Jones 24 Mar 2006 12:39
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