結果

問題 No.380 悪の台本
ユーザー masamasa
提出日時 2016-06-18 03:11:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 142 ms / 1,000 ms
コード長 1,226 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 65,956 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 14:32:13
合計ジャッジ時間 1,271 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

vector<string> names = {"digi", "petit", "rabi", "gema", "piyo"};
vector<string> tails = {"nyo",  "nyu",   "",     "gema", "pyo"};

bool check_tail(string &s, int idx) {
	int pos = s.rfind(tails[idx]);
	if (pos == string::npos) {
		return false;
	}
	string tail = s.substr(pos);
	if (tail.size() > tails[idx].size() + 3) {
		return false;
	}

	for (int k = tails[idx].size(); k < tail.size(); k++) {
		if (isalnum(tail[k])) {
			return false;
		}
	}

	return true;
}

bool check_rabi(string &s) {
	for (int j = 0; j < s.size(); j++) {
		if (isalnum(s[j])) {
			return true;
		}
	}
	return false;
}

int main() {
	string s;

	while (getline(cin, s)) {
		bool ok = false;
		for (int i = 0; i < names.size(); i++) {
			if (s.find(names[i] + " ") == 0) {
				s = s.substr(names[i].size() + 1);
				s = s.substr(max(0, (int) s.size() - 10));
				transform(s.begin(), s.end(), s.begin(), ::tolower);
				if (names[i] == "rabi") {
					ok = check_rabi(s);
				} else {
					ok = check_tail(s, i);
				}
				break;
			}
		}

		cout << (ok ? "CORRECT (maybe)" : "WRONG!") << endl;
	}

	return 0;
}
0