結果

問題 No.380 悪の台本
ユーザー tottoripapertottoripaper
提出日時 2018-03-11 16:55:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 1,000 ms
コード長 2,107 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 169,600 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 02:27:16
合計ジャッジ時間 2,491 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

string line;

bool isSymbol(char c){
    return !isalnum(c);
}

bool isDialogueWith(string str, string suffix){
    int s = str.size() - 1;
    while(s >= 0 && isSymbol(str[s])){
        --s;
    }

    int s_cnt = str.size() - 1 - s;
    if(s_cnt > 3){
        return false;
    }

    if(s + 1 < suffix.size()){
        return false;
    }
    
    string tail = str.substr(s - suffix.size() + 1, suffix.size());
    return tail == suffix;
}

bool isValid(){
    if(line.size() < 5){
        return false;
    }

    if(line.substr(0, 5) == "digi "){
        return isDialogueWith(line.substr(5), "nyo");
    }else if(line.substr(0, 5) == "rabi "){
        string tail = line.substr(5);
        return any_of(tail.begin(), tail.end(), [](char c){
                return isalnum(c);
            });
    }else if(line.substr(0, 5) == "gema "){
        return isDialogueWith(line.substr(5), "gema");
    }else if(line.substr(0, 5) == "piyo "){
        return isDialogueWith(line.substr(5), "pyo");
    }else if(line.size() >= 6 && line.substr(0, 6) == "petit "){
        return isDialogueWith(line.substr(6), "nyu");        
    }

    return false;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    while(true){        
        getline(cin, line);
        
        if(cin.eof()){
            break;
        }

        {
            int i = line.find(" ");
            if(i != string::npos){
                transform(line.begin() + i, line.end(), line.begin() + i, [](char c){
                        return tolower(c);
                    });
            }
        }
        
        if(isValid()){
            std::cout << "CORRECT (maybe)" << std::endl;
        }else{
            std::cout << "WRONG!" << std::endl;
        }
    }
}
0