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

Обсуждение задачи 2002. Тестовое задание

WA4
Послано Alexey Stulov 21 фев 2015 19:38
please can anyone tell me what is the test of 4?????

#include <iostream>

#include <conio.h>

using namespace std;

struct abonent
{
    char login[30];
    char password[30];
    short status;
};
int main()
{
    short n, k = 0, j, compare, index;
    char *part_str;
    char str[80];
    cin >> n;
    abonent *peop = new abonent[n];
    gets(str);
    for (int i = 0; i < n; i++)
    {
        gets(str);
        part_str = strtok(str, " ");
        if (!(strcmp(part_str, "register")))
        {
            part_str = strtok(NULL, " ");
            strcpy(peop[k].login, part_str);
            compare = 1;
            for (j = 0; j < k; j++)
            {
                if (!(strcmp(peop[k].login, peop[j].login)))
                {
                    compare = 0;
                    break;
                }
            }
            if (compare)
            {
                part_str = strtok(NULL, " ");
                strcpy(peop[k].password, part_str);
                peop[k].status = 0;
                k++;
                cout << "success: new user added\n";
            }
            else
            {
                cout << "fail: user already exists\n";
            }
        }

        if (!(strcmp(part_str, "login")))
        {
            part_str = strtok(NULL, " ");
            compare = 1;
            for (j = 0; j < k; j++)
            {
                if (!(strcmp(part_str, peop[j].login)))
                {
                    compare = 0;
                    index = j;
                    break;
                }
            }
            if (!compare)
            {
                part_str = strtok(NULL, " ");
                if (!(strcmp(part_str, peop[index].password)))
                {
                    if (peop[index].status)
                    {
                        cout << "fail: already logged in\n";
                    }
                    else
                    {
                        peop[index].status = 1;
                        cout << "success: user logged in\n";
                    }
                }
                else
                {
                    cout << "fail: incorrect password\n";
                }
            }
            else
            {
                cout << "fail: no such user\n";
            }
        }

        if (!(strcmp(part_str, "logout")))
        {
            part_str = strtok(NULL, " ");
            compare = 1;
            for (j = 0; j < k; j++)
            {
                if (!(strcmp(part_str, peop[j].login)))
                {
                    compare = 0;
                    index = j;
                    break;
                }
            }
            if (!compare)
            {
                if (peop[index].status)
                {
                    peop[index].status = 0;
                    cout << "success: user logged out\n";
                }
                else
                {
                    cout << "fail: already logged out\n";
                }
            }
            else
            {
                cout << "fail: no such user\n";
            }
        }
    }
    delete[] peop;
    return 0;
}

Edited by author 24.02.2015 02:52