結果
| 問題 |
No.380 悪の台本
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-06-16 15:17:48 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,436 bytes |
| コンパイル時間 | 2,445 ms |
| コンパイル使用メモリ | 83,388 KB |
| 実行使用メモリ | 59,464 KB |
| 最終ジャッジ日時 | 2024-11-06 22:30:50 |
| 合計ジャッジ時間 | 5,739 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 8 |
ソースコード
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();
if(who.contains("\n")){
System.out.println("WRONG!");
continue;
}
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;
}
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>0&&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;
}
}