結果
| 問題 |
No.380 悪の台本
|
| コンテスト | |
| ユーザー |
neko_the_shadow
|
| 提出日時 | 2019-05-17 17:12:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 577 ms / 1,000 ms |
| コード長 | 2,767 bytes |
| コンパイル時間 | 2,304 ms |
| コンパイル使用メモリ | 77,996 KB |
| 実行使用メモリ | 61,772 KB |
| 最終ジャッジ日時 | 2024-09-17 05:57:39 |
| 合計ジャッジ時間 | 4,560 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String line;
while ((line = stdin.readLine()) != null) {
String ans = isOK(line) ? "CORRECT (maybe)" : "WRONG!";
System.out.println(ans);
}
}
public static Set<Character> letters = new HashSet<>();
public static boolean isOK(String line) {
if (letters.isEmpty()) {
for (char ch = 'a'; ch <= 'z'; ch++) letters.add(ch);
for (char ch = 'A'; ch <= 'Z'; ch++) letters.add(ch);
for (char ch = '0'; ch <= '9'; ch++) letters.add(ch);
}
// 1行を最大2つに分割。分割できない場合は異常。
String[] tokens = line.split(" ", 2);
if (tokens.length != 2) {
return false;
}
String who = tokens[0];
String speech = tokens[1].toLowerCase();
// digiの全てのセリフはnyoか,nyoの末尾に記号を1~3文字つけたもので終わる
// petitの全てのセリフはnyuか,nyuの末尾に記号を1~3文字つけたもので終わる
// gemaの全てのセリフはgemaか,gemaの末尾に記号を1~3文字つけたもので終わる
// piyoの全てのセリフはpyoか,pyoの末尾に記号を1~3文字つけたもので終わる
if (who.equals("digi")) return endsWith(speech, "nyo");
if (who.equals("petit")) return endsWith(speech, "nyu");
if (who.equals("gema")) return endsWith(speech, "gema");
if (who.equals("piyo")) return endsWith(speech, "pyo");
// rabiの全てのセリフは記号でない文字を少なくても1文字含む
if (who.equals("rabi")) {
for (char ch : speech.toCharArray()) {
if (letters.contains(ch)) return true;
}
return false;
}
// だれともマッチしなかった。
return false;
}
public static boolean endsWith(String word, String suffix) {
// 最大3個まで末尾の記号を除去する。
for (int i = 0; i < 3; i++) {
if (word.isEmpty()) {
break;
}
char c = word.charAt(word.length() - 1);
if (letters.contains(c)) {
break;
}
word = word.substring(0, word.length() - 1);
}
return word.endsWith(suffix);
}
}
neko_the_shadow