結果

問題 No.380 悪の台本
ユーザー face4face4
提出日時 2018-09-04 11:06:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 1,995 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 75,240 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 00:38:02
合計ジャッジ時間 1,397 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 相当めんどくさい、空白の処理やらなにやら
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define print(x, a, b) if(x) cout << a << endl; else cout << b << endl

bool isSymbol(char x){
    bool small = 'a' <= x && x <= 'z';
    bool large = 'A' <= x && x <= 'Z';
    bool number = '0' <= x && x <= '9';
    if(small || large || number)    return false;
    else                            return true;
}

bool startsWith(string str, string pre){
    int s = str.length(), p = pre.length();
    if(s < p)   return false;

    int j;
    for(j = 0; j < p; j++){ 
        if(str[j] != pre[j])  break;
    }

    return j == p;
}

bool check(string s, string gobi){
    reverse(s.begin(), s.end());
    reverse(gobi.begin(), gobi.end());

    int pos = 0;
    while(pos < s.length() && isSymbol(s[pos])){
        pos++;
    }

    if(pos > 3) return false;

    bool judge = true;
    for(int i = 0; i < gobi.length(); i++){
        if(pos+i > s.length()-1 || isSymbol(s[pos+i]))  judge = false;
        else                    s[pos+i] = tolower(s[pos+i]);
    }

    if(!judge)  return false;

    return startsWith(s.substr(pos), gobi);
}

string people[5] = {"digi ", "petit ", "gema ", "piyo ", "rabi "};
string suffix[4] = {"nyo", "nyu", "gema", "pyo"};

int main(){
    string s;
    while(getline(cin, s)){
        int person;
        for(person = 0; person < 5; person++){
            if(startsWith(s, people[person]))   break;
        }

        if(person == 5){
            cout << "WRONG!" << endl;
            continue;
        }

        if(person == 4){
            bool judge = false;
            for(int i = people[person].length(); i < s.size(); i++){
                if(!isSymbol(s[i]))    judge = true;
            }
            print(judge, "CORRECT (maybe)", "WRONG!");
            continue;
        }

        print(check(s.substr(people[person].length()), suffix[person]) ,"CORRECT (maybe)", "WRONG!");
    }
    return 0;
}
0