-
Notifications
You must be signed in to change notification settings - Fork 0
/
SketchleyPark.java
62 lines (61 loc) · 1.96 KB
/
SketchleyPark.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.io.*;
import java.util.*;
public class SketchleyPark {
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String msg = br.readLine();//HAILHYDRA -> 9 letters long
int ke = Integer.parseInt(br.readLine());
HashMap<Integer,String> pmgs = new HashMap<Integer,String>();
String t;
int o = 0;
boolean hail = false;
for(int i = 0; i < msg.length()-8;i++){
t = msg.substring(i,i+9);
if(t.charAt(0) == t.charAt(4) && t.charAt(1) == t.charAt(8)){
Set<Character> u = new HashSet<Character>();
if(t.charAt(0) != t.charAt(2) && t.charAt(1) != t.charAt(2))u.add(t.charAt(2));
if(t.charAt(0) != t.charAt(3) && t.charAt(1) != t.charAt(3))u.add(t.charAt(3));
if(t.charAt(0) != t.charAt(5) && t.charAt(1) != t.charAt(5))u.add(t.charAt(5));
if(t.charAt(0) != t.charAt(6) && t.charAt(1) != t.charAt(6))u.add(t.charAt(6));
if(t.charAt(0) != t.charAt(7) && t.charAt(1) != t.charAt(7))u.add(t.charAt(7));
if(u.size() == 5){
pmgs.put(o,t);
o++;
}
}
}
if(pmgs.size() > 0){
String key = "";
char[] hydra = new char[9];
check:
for(int i = 0; i < ke; i++){
key = br.readLine();
hydra[0] = key.charAt(7);//H
hydra[1] = key.charAt(0);//A
hydra[2] = key.charAt(8);//I
hydra[3] = key.charAt(11);//L
hydra[4] = hydra[0];//H
hydra[5] = key.charAt(24);//Y
hydra[6] = key.charAt(3);//D
hydra[7] = key.charAt(17);//R
hydra[8] = hydra[1];//A
t = new String(hydra);
for(int j = 0; j < pmgs.size();j++){
if(pmgs.get(j).equals(t)){
hail = true;
break check;
}
}
}
if(hail){
char[] res = new char[msg.length()];
for(int i = 0; i < msg.length();i++){
res[i] =(char)(key.indexOf(msg.charAt(i)) + 65);
}
System.out.println(res);
}
else System.out.println("KeyNotFoundError");
}
else System.out.println("KeyNotFoundError");
}
}