-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.kt
73 lines (68 loc) · 1.63 KB
/
solution.kt
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
63
64
65
66
67
68
69
70
71
72
73
// Mapping Table, empty if same.
// a b k d e g h i l m n ng o p r s t u w y
// c j l m n
fun parse(text: String): String {
val result = StringBuilder()
var beforeN = false
for (c in text) {
if (beforeN) {
beforeN = false
if (c == 'g') {
result.append('n')
continue
} else {
result.append('m')
}
}
when (c) {
'n' -> {
beforeN = true
}
'k' -> {
result.append('c')
}
'l' -> {
result.append('j')
}
'm' -> {
result.append('l')
}
else -> {
result.append(c)
}
}
}
if (beforeN) result.append('m')
return result.toString()
}
fun decrypt(input: String): String {
val result = StringBuilder()
for (c in input) {
when (c) {
'c' -> {
result.append('k')
}
'j' -> {
result.append('l')
}
'l' -> {
result.append('m')
}
'm' -> {
result.append('n')
}
'n' -> {
result.append("ng")
}
else -> {
result.append(c)
}
}
}
return result.toString()
}
fun main(args: Array<out String>) {
List(readLine()!!.toInt()) { parse(readLine()!!) }.sorted().forEach {
println(decrypt(it))
}
}