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

Обсуждение задачи 1027. Снова D++

help me with test #1, please
Послано Squid 3 янв 2006 21:29
i've tested my program on all tests contained in the forum.
but still i got WA on test #1

#include <iostream>

enum State {ERROR, TEXT, BRACKET, ARITHMETIC, COMMENT, STAR};

int main() {
    State state = TEXT;
    char ch;
    int count = 0;    // number of nested brackets

    while (!std::cin.eof()) {
        std::cin >> ch;
        if (ch == '#') // for testing only
            break;
        if (state == TEXT) {
            if (ch == ')') {
                state = ERROR;
                break;
            } else if (ch == '(') {
                state = BRACKET;
                count++;
            }
        } else if (state == BRACKET) {
            if (ch == ')') {
                count--;
                if (count == 0)
                    state = TEXT;
            } else if (ch == '(') {
                count++;
            } else if ((ch >= '0' && ch <= '9') || (ch == '=') || (ch == '+') ||
                (ch == '-') || (ch == '/') || (ch == '\n') || (ch == '\r')) {
                    state = ARITHMETIC;
            } else if (ch == '*') {
                count--;
                state = COMMENT;
            } else {
                state = ERROR;
                break;
            }
        } else if (state == ARITHMETIC) {
            if (ch == ')') {
                count--;
                if (count == 0)
                    state = TEXT;
            } else if (ch == '(') {
                count++;
                state = BRACKET;
            } else if ((ch >= '0' && ch <= '9') || (ch == '=') || (ch == '+') ||
                (ch == '-') || (ch == '*') || (ch == '/') || (ch == '\n') || (ch == '\r')) {
                //nothing
            } else {
                state = ERROR;
                break;
            }
        } else if (state == COMMENT) {
            if (ch == '*') {
                state = STAR;
            }
        } else if (state == STAR) {
            if (ch == ')') {
                state = (count > 0) ? ARITHMETIC : TEXT;
            } else if (ch == '*') {
                // nothing
            } else {
                state = COMMENT;
            }
        }
    }

    if (state == TEXT) {
        std::cout << "YES";
    } else {
        std::cout << "NO";
    }

    return 0;
}
Re: help me with test #1, please
Послано Ras Misha [t4ce] 16 янв 2006 14:14
(123
321)

asnwer - YES
Re: help me with test #1, please
Послано Squid 19 янв 2006 02:56
On your test my program worked correctly.
But anyway, you help me to find my bug.
Thanks a lot.
PS
I used std::cin and it ignores spaces... :-/