-
Notifications
You must be signed in to change notification settings - Fork 0
/
P5430.kt
46 lines (42 loc) · 1.19 KB
/
P5430.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
fun main() {
var T = readLine()!!.toInt()
while (T-- != 0) {
val p = readLine().toString()
val n = readLine()!!.toInt()
var arr: List<String> = readLine()
.toString()
.replace("[", "")
.replace("]", "")
.split(",")
var flag = false
var revFlag = false
p.forEach {
if (it == 'R') {
revFlag = !revFlag
} else if (it == 'D') {
if (arr.isEmpty()) {
flag = true
return@forEach
}
arr = if (revFlag) arr.dropLast(1) else arr.drop(1)
}
}
if (flag || arr.isEmpty()) {
println("error")
} else {
print("[")
if (revFlag) {
for (i in arr.size - 1 downTo 0) {
print(arr[i])
if (i == arr.size - 1) print(",")
}
} else {
for (i in arr.indices) {
print(arr[i])
if (i != arr.size - 1) print(",")
}
}
println("]")
}
}
}