結果

問題 No.380 悪の台本
ユーザー 37zigen37zigen
提出日時 2016-06-16 15:06:14
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 2,335 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 83,056 KB
実行使用メモリ 43,232 KB
最終ジャッジ日時 2024-04-24 14:09:00
合計ジャッジ時間 4,576 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 128 ms
41,160 KB
testcase_03 AC 130 ms
41,048 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.io.UnsupportedEncodingException;
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<>();
	byte[] digi;
	byte[] petit;
	byte[] gema;
	byte[] piyo;

	@SuppressWarnings("unchecked")
	void solver() {
		byte[] l = null;
		byte[] d = null;
		try {
			d = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789".getBytes("US-ASCII");
			digi = "nyo".getBytes("US-ASCII");
			petit = "nyu".getBytes("US-ASCII");
			gema = "gema".getBytes("US-ASCII");
			piyo = "pyo".getBytes("US-ASCII");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		for (int i = 0; i < d.length; i++) {
			nonsymbol.add(d[i]);
		}

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

	boolean isCorrect(String who, String line) {
		byte[] asciiCodes = null;
		try {
			asciiCodes = line.getBytes("US-ASCII");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		if (who.equals("digi")) {
			if(bottom(digi, asciiCodes)){
				return true;
			}
		} else if (who.equals("petit")) {
			if(bottom(petit,asciiCodes)){
				return true;
			}
		} else if (who.equals("rabi")) {
			for(int i=0;i<asciiCodes.length;i++){
				if(nonsymbol.contains(asciiCodes[i])){
					return true;
				}
			}
		} else if (who.equals("gema")) {
			if(bottom(gema,asciiCodes)){
				return true;
			}
		} else if (who.equals("piyo")) {
			if(bottom(piyo,asciiCodes)){
				return true;
			}
		} else {
			throw new AssertionError("who is " + who + " ?");
		}
		return false;
	}

	boolean bottom(byte[] bottom, byte[] code) {
		int n = bottom.length;
		int len = code.length;
		for (int i = 0; i < 4; i++) {
			boolean f = true;
			for (int j = (len - 1) - (n - 1) - i; j < len - i; j++) {
				if (bottom[j - (len - 1) + (n - 1) + i] != code[j]) {
					f = false;
				}
			}
			for (int j = len - i; j < len; j++) {
				if (nonsymbol.contains(code[j])) {
					f = false;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}
}
0