fork download
  1. import java.util.LinkedList
  2. import java.util.StringTokenizer
  3.  
  4. fun main() {
  5. val br = System.`in`.bufferedReader()
  6. val queue = LinkedList<String>()
  7.  
  8. val str = br.readLine()
  9. val m = br.readLine().toInt()
  10.  
  11. var index = 0
  12. repeat(m) {
  13. val token = StringTokenizer(br.readLine())
  14. when (token.nextToken()) {
  15. "L" -> { if (index > 0) index-- }
  16. "D" -> { if (index < queue.size) index++ }
  17. "B" -> {
  18. if (index > 0) {
  19. index--
  20. queue.removeAt(index)
  21. }
  22. }
  23. "P" -> {
  24. queue.add(index, token.nextToken())
  25. index++
  26. }
  27. }
  28. println(queue)
  29. }
  30.  
  31. val sb = StringBuilder()
  32. for (c in queue) {
  33. sb.append(c)
  34. }
  35. println(sb)
  36. }
Success #stdin #stdout 0.07s 38196KB
stdin
abc
9
L
L
L
L
L
P x
L
B
P y
stdout
[]
[]
[]
[]
[]
[x]
[x]
[x]
[y, x]
yx