結果

問題 No.380 悪の台本
ユーザー hogeover30hogeover30
提出日時 2016-06-18 03:52:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 1,176 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 79,612 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 14:32:19
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 17 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 140 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <map>
#include <cctype>
using namespace std;

map<string, string> suffix;

bool correct(const string& words, const string& name)
{
    if (name=="rabi") {
        for(auto& c: words) if (isalnum(c)) return true;
        return false;
    }
    if (!suffix.count(name)) return false;

    string suf=suffix[name];
    int m=suf.size();
    if (words.size()+3<m) return false;

    int n=words.size();
    for(int i=n-1; i>=n-4; --i) if (isalnum(words[i])) {
        if (i+1<m) return false;
        return words.substr(i+1-m, m)==suf;
    }
    return false;
}

int main()
{
    string names[]={"digi", "petit", "gema", "piyo"};
    string suffs[]={"nyo", "nyu", "gema", "pyo"};
    for(int i=0; i<4; ++i) suffix[names[i]]=suffs[i];

    string s;
    while (getline(cin, s)) {
        auto k=s.find(' ');
        if (k!=s.npos and k+1<s.size()) {
            string name=s.substr(0, k);
            string words=s.substr(k+1);
            for(auto& c: words) c=tolower(c);
            cout<<(correct(words, name) ? "CORRECT (maybe)" : "WRONG!")<<endl;
        }
        else {
            cout<<"WRONG!"<<endl;
        }
    }
}
0