ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1269. Антимат

WA #5
Послано Scythe (Berinde Radu) 1 авг 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
Послано Benone Sinulescu aka Benny 3 авг 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.