結果

問題 No.380 悪の台本
ユーザー 37zigen37zigen
提出日時 2016-06-16 18:14:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,808 bytes
コンパイル時間 2,403 ms
コンパイル使用メモリ 80,052 KB
実行使用メモリ 47,520 KB
最終ジャッジ日時 2024-04-24 14:11:50
合計ジャッジ時間 4,644 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package yukicoder;

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[] 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 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)!='0')return false;
		byte[] asciiCodes = null;
		if (line == null)
			return false;
		try {
			asciiCodes = line.getBytes("US-ASCII");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		if (num==0) {
			if (bottom(digi, asciiCodes)) {
				return true;
			}
		} else if (num==1) {
			if (bottom(petit, asciiCodes)) {
				return true;
			}
		} else if (num==2) {
			for (int i = 0; i < asciiCodes.length; i++) {
				if (nonsymbol.contains(asciiCodes[i])) {
					return true;
				}
			}
		} else if (num==3) {
			if (bottom(gema, asciiCodes)) {
				return true;
			}
		} else if (num==4) {
			if (bottom(piyo, asciiCodes)) {
				return true;
			}
		} else if(num==-1){
			return false;
		}else{
			throw new AssertionError("error");
		}
		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 = false;
			for (int j = (len - 1) - (n - 1) - i; j >= 0 && j < len - i; j++) {
				f = true;
				if (bottom[j - (len - 1) + (n - 1) + i] != code[j]) {
					f = false;
					break;
				}
			}
			for (int j = len - i; j >= 0 && j < len; j++) {
				if (nonsymbol.contains(code[j])) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}
}
0