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

Обсуждение задачи 1488. Покер-АСМ

Where is the bug?!!!
Послано Howl of Despair 5 фев 2008 00:52
I don't know how this did happen... It's the first time I've been encountered with such a trouble... Everything seems to be correct, all "home" tests having passed, but... WA2
Somebody, please help me!

My code:
#include <cstdio>
#include <algorithm>
using namespace std;

struct Card
{
    int value;
    char color;
    Card(int value = 0, char color = 0) : value(value), color(color) {}
    bool in()
    {
        char c;
        while(1)
        {
            c = getchar();
            if(c == EOF)
                return false;
            if((c >= '1') && (c <= '9'))
                break;
            if(c == 'A' || c == 'J' || c == 'Q' || c == 'K')
                break;
            if(c >= 'A' && c <= 'Z')
                for(;;);
            if(c >= 'a' && c <= 'z')
                for(;;);
            if(c == '0')
                for(;;);
        }
        switch(c)
        {
            case '1':
                value = 10;
                getchar();
                break;
            case 'J':
                value = 11;
                break;
            case 'Q':
                value = 12;
                break;
            case 'K':
                value = 13;
                break;
            case 'A':
                value = 14;
                break;
            default:
                if(c < '1' || c > '9')
                    for(;;);
                value = c - '0';
        }
        color = getchar();
        if(!(color == 'H' || color == 'D' || color == 'S' || color == 'C'))
            for(;;);
        if(value < 1 || value > 14)
            for(;;);
        return true;
    }
};

bool operator<(Card c1, Card c2)
{
    return c1.value < c2.value;
}

bool operator==(Card c1, Card c2)
{
    return (c1.value == c2.value) && (c1.color == c2.color);
}

enum cname {SINGLE = 1, PAIR = 2, FLASH = 3, STREET = 4, THREE = 5, STREETFLASH = 6, MAJOR = 7};
struct Combination
{
    cname Name;
    int val;
    Combination() {}
    Combination(Card *cds)
    {
        sort(cds, cds + 3);
        if((cds[0].value == cds[1].value) && (cds[1].value == cds[2].value))
        {
            if(cds[0].value == 3)
                Name = MAJOR;
            else
            {
                Name = THREE;
                val = cds[0].value;
            }
            return;
        }
        if((cds[0].color == cds[1].color) && (cds[1].color == cds[2].color))
        {
            if((cds[0].value + 1 == cds[1].value) && (cds[0].value + 2 == cds[2].value))
            {
                Name = STREETFLASH;
                val = cds[2].value;
            }
            else
            {
                Name = FLASH;
                val = 10000 * cds[2].value + 100 * cds[1].value + cds[0].value;
            }
            return;
        }
        if((cds[0].value + 1 == cds[1].value) && (cds[0].value + 2 == cds[2].value))
        {
            Name = STREET;
            val = cds[2].value;
            return;
        }
        if(cds[1].value == cds[2].value)
        {
            Name = PAIR;
            val = 100 * cds[1].value + cds[0].value;
            return;
        }
        if(cds[1].value == cds[0].value)
        {
            Name = PAIR;
            val = 100 * cds[1].value + cds[2].value;
            return;
        }
        Name = SINGLE;
        val = 10000 * cds[2].value + 100 * cds[1].value + cds[0].value;
    }
};

bool operator<(Combination c1, Combination c2)
{
    if((int)c1.Name == (int)c2.Name)
    {
        return c1.val < c2.val;
    }
    return (int)c1.Name < (int)c2.Name;
}

bool operator==(Combination c1, Combination c2)
{
    return (c1.Name == c2.Name) && (c1.val == c2.val);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Card Sasha[3], Dima[5];
    char Winner[3][10] = {"Sasha", "Artyom", "Dima"};
    int dc;
    while(1)
    {
        dc = 3;
        for(int i = 0; i < 3; ++i)
            Sasha[i].in();
        for(int i = 0; i < 3; ++i)
            Dima[i].in();
        dc = 3;
        for(int i = 0; i < 2; ++i)
        {
            Card cheat;
            if(cheat.in() == false)
                return 0;
            bool ok = true;
            for(int k = 0; k < 3; ++k)
            {
                if(cheat == Dima[k] || cheat == Sasha[k])
                {
                    ok = false;
                    break;
                }
            }
            if(cheat == Dima[dc - 1])
                ok = false;
            if(ok)
                Dima[dc++] = cheat;
        }
        Combination SComb(Sasha);
        Combination DComb;
        int res = 0;
        Card comb[3];
        for(int i = 0; i < dc - 2; ++i)
        {
            comb[0] = Dima[i];
            for(int j = i + 1; j < dc - 1; ++j)
            {
                comb[1] = Dima[j];
                for(int k = j + 1; k < dc; ++k)
                {
                    comb[2] = Dima[k];
                    DComb = Combination(comb);
                    if(SComb < DComb)
                        res = 2;
                    else if(DComb == SComb)
                        res = max(res, 1);
                }
            }
        }
        puts(Winner[res]);
    }
   //    return 0;
}