結果

問題 No.380 悪の台本
ユーザー 37zigen37zigen
提出日時 2016-06-16 18:58:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 919 ms / 1,000 ms
コード長 2,428 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 79,464 KB
実行使用メモリ 53,656 KB
最終ジャッジ日時 2024-04-24 14:13:29
合計ジャッジ時間 5,552 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
39,732 KB
testcase_01 AC 109 ms
39,876 KB
testcase_02 AC 108 ms
39,868 KB
testcase_03 AC 111 ms
40,584 KB
testcase_04 AC 263 ms
44,696 KB
testcase_05 AC 346 ms
46,392 KB
testcase_06 AC 331 ms
46,468 KB
testcase_07 AC 919 ms
53,656 KB
testcase_08 AC 217 ms
43,040 KB
testcase_09 AC 274 ms
45,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		new Main().solver();
	}

	Set lowcase = new HashSet<>();
	Set nonsymbol = new HashSet<>();
	String digi_end = "nyo";
	String petit_end = "nyu";
	String gema_end = "gema";
	String piyo_end = "pyo";

	@SuppressWarnings("unchecked")
	void solver() {
		String d = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		for (int i = 0; i < d.length(); i++) {
			nonsymbol.add(d.charAt(i));
		}

		Scanner sc = new Scanner(System.in);
		while (sc.hasNextLine()) {
			String line = sc.nextLine();
			if (isCorrect(line)) {
				System.out.println("CORRECT (maybe)");
			} else {
				System.out.println("WRONG!");
			}
		}
	}

	String[] name = { "digi", "petit", "rabi", "gema", "piyo" };

	boolean isCorrect(String line) {

		int num = -1;
		out: for (int i = 0; i < 5; i++) {
			for (int j = 0; j < line.length() && j < name[i].length(); j++) {
				if (line.charAt(j) != name[i].charAt(j)) {
					break;
				}
				if (j == name[i].length() - 1) {
					num = i;
					line = line.substring(name[i].length()).toLowerCase();
					break out;
				}
			}
		}
		if (line.length() == 0)
			return false;
		if (line.charAt(0) != ' ')
			return false;
		line=line.substring(1);
		if (num == 0) {
			if (bottom(digi_end, line)) {
				return true;
			}
		} else if (num == 1) {
			if (bottom(petit_end, line)) {
				return true;
			}
		} else if (num == 2) {
			for (int i = 0; i < line.length(); i++) {
				if (nonsymbol.contains(line.charAt(i))) {
					return true;
				}
			}
		} else if (num == 3) {
			if (bottom(gema_end, line)) {
				return true;
			}
		} else if (num == 4) {
			if (bottom(piyo_end, line)) {
				return true;
			}
		} else if (num == -1) {
			return false;
		} else {
			throw new AssertionError("error");
		}
		return false;
	}

	boolean bottom(String bottom, String line) {
		int n = bottom.length();
		int len = line.length();
		for (int i = 0; i < 4; i++) {
			boolean f = false;
			for (int j = len - n  -i; j >= 0 && j < len - i; j++) {
				f = true;
				if (bottom.charAt(j - len + n + i) != line.charAt(j)) {
					f = false;
					break;
				}
			}
			for (int j = len - i; j >= 0 && j < len; j++) {
				if (nonsymbol.contains(line.charAt(j))) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}
}
0