結果

問題 No.380 悪の台本
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-07-05 18:12:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 164 ms / 1,000 ms
コード長 1,998 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 173,532 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 14:39:05
合計ジャッジ時間 2,327 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 19 ms
5,376 KB
testcase_06 AC 18 ms
5,376 KB
testcase_07 AC 164 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    bool check_rabi(string t) {
        for (int i = 0; i < t.size(); i++) {
            if (isdigit(t[i]) || isalpha(t[i])) {
                return true;
            }
        }
        return false;
    }

    map<string, string> M;
    void init() {
        M["digi"] = "nyo";
        M["petit"] = "nyu";
        M["gema"] = "gema";
        M["piyo"] = "pyo";
    }

    bool check(string c, string t) {
        if (c == "rabi") return check_rabi(t);
        if (M.count(c) == 0) return false;
        string last = M[c];
        int count = 0;
        for (int i = t.size() - 1; i >= 0; i--) {
            if (not (isdigit(t[i]) || isalpha(t[i]))) {
                count++;
            } else {
                break;
            }
        }
        if (count > 3) return false;
        if (count + last.size() > t.size()) return false;
        t = t.substr(0, t.size() - count);

        return t.substr(t.size() - last.size(), last.size()) == last;
    }

    void solve() {
        init();
        string s;
        while (getline(cin, s)) {
            if (s[0] == ' ') {
                cout << "WRONG!" << endl;
                continue;
            }
            istringstream is(s);
            string c; is >> c;
            string t = s.substr(c.size(), s.size() - c.size());
            for (auto& x : t) x = tolower(x);
            cout << (check(c, t) ? "CORRECT (maybe)" : "WRONG!") << endl;
        }
    }
}

int main() {
    solve();
    return 0;
}

0