#K59067. Array Operations

    ID: 30782 Type: Default 1000ms 256MiB

Array Operations

Array Operations

You are given an array along with a command to perform one of three operations: rotate, sum, or delete. Your task is to implement a program that reads multiple test cases from standard input and performs the specified operation.

Operations

  • rotate: Rotate the array to the right by \(X\) positions. The rotated array is obtained by moving the last \(X \mod N\) elements to the beginning.
  • sum: Compute the sum of the elements at even indices (0-indexed) of the array.
  • delete: Remove all occurrences of a given value \(Y\) from the array. If all elements are removed, output "empty".

Note: Array indices are 0-indexed.

inputFormat

The first line contains an integer \(T\), the number of test cases. Each test case begins with a command which is either "rotate", "sum", or "delete".

  • If the command is "rotate":
    • The next integer \(N\) denotes the size of the array.
    • The next \(N\) integers denote the elements of the array.
    • The following integer \(X\) indicates the number of positions to rotate to the right.
  • If the command is "sum":
    • The next integer \(N\) denotes the size of the array.
    • The next \(N\) integers denote the elements of the array.
  • If the command is "delete":
    • The next integer \(N\) denotes the size of the array.
    • The next \(N\) integers denote the elements of the array.
    • The following integer \(Y\) indicates the value to be removed.

outputFormat

For each test case, output the result on a separate line:

  • For "rotate": Output the rotated array elements separated by a single space.
  • For "sum": Output the sum of the elements at even indices.
  • For "delete": Output the resulting array elements separated by a single space. If the resulting array is empty, output "empty".
## sample
5
rotate
6
1 2 3 4 5 6
2
rotate
4
1 2 3 4
5
sum
6
1 2 3 4 5 6
delete
7
1 2 3 4 2 5 2
2
delete
3
1 1 1
1
5 6 1 2 3 4

4 1 2 3 9 1 3 4 5 empty

</p>