[BaekJoon] 25594번 - HG 음성기호 [Java]
[BaekJoon] 25594번 - HG 음성기호 [Java]
1. 문제 풀이
HG 표준음성기호로 암호화된 문자열을 원래 문자열로 복호화할 수 있는지 판단하는 문제로 주어진 문자열에서 현재 바라보는 인덱스를 기준으로 해당 문자로 만들 수 있는 코드로 현재 위치에서 시작하면 복호화가 가능하다는 점을 통해 해당 과정을 전체 문자열에 대해 반복해주면 된다.
2. 코드
1. 풀이 [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
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
Map<Character, String> map = new HashMap<>();
map.put('a', "aespa");
map.put('b', "baekjoon");
map.put('c', "cau");
map.put('d', "debug");
map.put('e', "edge");
map.put('f', "firefox");
map.put('g', "golang");
map.put('h', "haegang");
map.put('i', "iu");
map.put('j', "java");
map.put('k', "kotlin");
map.put('l', "lol");
map.put('m', "mips");
map.put('n', "null");
map.put('o', "os");
map.put('p', "python");
map.put('q', "query");
map.put('r', "roka");
map.put('s', "solvedac");
map.put('t', "tod");
map.put('u', "unix");
map.put('v', "virus");
map.put('w', "whale");
map.put('x', "xcode");
map.put('y', "yahoo");
map.put('z', "zebra");
String str = br.readLine();
boolean flag = true;
for (int i = 0; i < str.length(); i++) {
String code = map.get(str.charAt(i));
if (str.startsWith(code, i)) {
sb.append(str.charAt(i));
i += code.length() - 1;
} else {
flag = false;
break;
}
}
if (flag) {
System.out.println("It's HG!");
System.out.println(sb);
} else {
System.out.println("ERROR!");
}
}
}
This post is licensed under CC BY 4.0 by the author.