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 1269. Obscene Words Filter

WA #5
Posted by Scythe (Berinde Radu) 1 Aug 2004 12:27
I keep WA-ing on test #5. So I wrote a bruteforce program (using strstr) and still WA #5. From what I could figure out, test 5 is the first one that has blank lines. I pass the test 5 when displaying "Passed" instead of my result. I am not sure how that is possible (strstr should work fine) even if there is extra data in the input file (gets reads one line at a time).
When reading the number of lines i use scanf("%d%*c", &nr) in order to skip exactly one end of line character. Is this correct?

Below is part of my code.
Any suggestions would be much appreciated.
Thanks


void read_words()
{
    int i;
    scanf("%d\n", &N);
    for (i = 0; i < N; i++)
    {
        Words[i] = WordBuf + Bufpos;
        gets(Words[i]);
        Wlen[i] = strlen(Words[i]);
        Bufpos += Wlen[i] + 1;
    }
}

void read_and_solve()
{
    int i, l, totlines = 0, o;
    char *x;
    scanf("%d%*c", &totlines);
    for (l = 1; l <= totlines; l++)
    {
        if (gets(Text) == NULL)
          while(1) printf("blahblah");
        for (i = 0, o = 900001; i < N; i++)
            if ((x = strstr(Text, Words[i])) &&
                o > x-Text)
                o = x-Text;
        if (o < 900001) /* if on test 5 this if is skipped, test 5 is passed */
        {
            printf("%d %d\n", l, o+1);
            return;
        }
    }
    printf("Passed\n");
}
Problem solved
Posted by Benone Sinulescu aka Benny 3 Aug 2004 13:14
The problem was when reading the words. If the first word began with some empty spaces, the scanf("%d\n", &N) would skip those. scanf("%d%*c", &N) fixes that.