#K8341. Viewing List Manipulation

    ID: 36191 Type: Default 1000ms 256MiB

Viewing List Manipulation

Viewing List Manipulation

In this problem, you are given several test cases, each consisting of a sequence of operations to perform on an initially empty viewing list. The operations include:

  1. (\texttt{ADD\ x}): Append movie (x) to the end of the list.
  2. (\texttt{REMOVE\ x}): Remove the first occurrence of movie (x) if it exists.
  3. (\texttt{REVERSE}): Reverse the order of the viewing list.
  4. (\texttt{ROTATE\ n}): Rotate the list to the right by (n) positions, meaning the last (n) elements move to the front. (n) is a non-negative integer and the effective rotation is (n \bmod L) where (L) is the current length of the list.

After processing all the operations of a test case, if the list is empty, output the string "EMPTY"; otherwise, output the movies in the list separated by a single space. Each test case’s output should be printed on a new line.

Make sure your solution reads from standard input and writes to standard output.

inputFormat

The input begins with an integer (T) representing the number of test cases. For each test case, the first line contains an integer (N) representing the number of operations. The next (N) lines each contain one of the following operations: "ADD x", "REMOVE x", "REVERSE", or "ROTATE n".

outputFormat

For each test case, output a single line representing the final state of the viewing list after performing all operations. If the list is empty, print "EMPTY"; otherwise, print the names of the movies separated by a single space.## sample

2
5
ADD inception
ADD matrix
REMOVE inception
ADD avatar
REVERSE
3
ADD starwars
ROTATE 1
REVERSE
avatar matrix

starwars

</p>