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. }
  29.  
  30. val sb = StringBuilder()
  31. for (c in queue) {
  32. sb.append(c)
  33. }
  34. println(sb)
  35. }
Success #stdin #stdout 0.07s 39908KB
stdin
abc
9
L
L
L
L
L
P x
L
B
P y
stdout
yx