結果

問題 No.769 UNOシミュレータ
ユーザー greentea011greentea011
提出日時 2019-03-14 11:41:15
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,495 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 77,228 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 00:32:35
合計ジャッジ時間 2,499 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 29 ms
5,376 KB
testcase_13 AC 29 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 56 ms
5,376 KB
testcase_16 AC 56 ms
5,376 KB
testcase_17 AC 56 ms
5,376 KB
testcase_18 AC 83 ms
5,376 KB
testcase_19 AC 84 ms
5,376 KB
testcase_20 AC 83 ms
5,376 KB
testcase_21 AC 85 ms
5,376 KB
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <string>
#include <map>
#include <functional>
#include <stdio.h>

struct uno {
    int n;
    int *p;
    int now;
    int d2cnt;
    int d4cnt;
    int rvflg;

    void init(int player) {
        n = player;
        p = new int[n];
        for (int i=0;i<n;i++) p[i]=0;
        now=0;
        d2cnt=0;
        d4cnt=0;
        rvflg=1;
    };
    void next() {
        now = (now+n+rvflg)%n;
    };
    void f(const std::string& type) {
        static std::map<std::string, std::function<void ()>> table = {
            { "number",   [this](){p[now]++;} },
            { "drawtwo",  [this](){p[now]++;d2cnt+=2;} },
            { "drawfour", [this](){p[now]++;d4cnt+=4;} },
            { "skip",     [this](){p[now]++;next();} },
            { "reverse",  [this](){p[now]++;rvflg=-rvflg;} },
        };

        if ((d2cnt!=0)&&(type!="drawtwo")) {
            p[now]-=d2cnt;
            d2cnt=0;
            next();
        }
        if ((d4cnt!=0)&&(type!="drawfour")) {
            p[now]-=d4cnt;
            d4cnt=0;
            next();
        }
        table[type]();
    };
    int getWinner() {return now;};
    int getCard(int player) {return p[player];};
};

int main() {
    int n,m;
    scanf("%d %d", &n, &m);
    struct uno Uno;
    Uno.init(n);
    for (int i=0;i<m;i++) {
        std::string s;
        std::cin >> s;
        Uno.f(s);
        if (i!=(m-1)) Uno.next();
    }
    printf("%d %d\n", Uno.getWinner()+1, Uno.getCard(Uno.getWinner()));
}
0