-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP5397.kt
37 lines (36 loc) · 1.15 KB
/
P5397.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
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*
fun main() {
var cursor: Int
val password = LinkedList<Char>()
BufferedReader(InputStreamReader(System.`in`))
.lineSequence()
.drop(1)
.joinToString("\n") {
cursor = 0
password.clear()
for (char in it.toCharArray()) {
when (char) {
'<' -> {
if (cursor > 0) cursor--
}
'>' -> {
if (cursor < password.size) cursor++
}
'-' -> {
if (cursor > 0) {
cursor--
password.removeAt(cursor)
}
}
else -> {
password.add(cursor, char)
cursor++
}
}
}
password.joinToString("")
}
.let(::println)
}