#C7689. Array Manipulation Toolkit
Array Manipulation Toolkit
Array Manipulation Toolkit
In this problem, you are required to implement a set of array manipulation operations. You will handle multiple test cases. For each test case, you will be given an operation code and an array (and in one operation, an extra integer parameter). The operations are defined as follows:
- Reverse Array: Given an array, output its reverse.
- Sum Elements: Output the sum of all elements in the array.
- Remove Duplicates: Remove duplicate elements from the array while preserving the original order.
- Rotate Array: Rotate the array to the right by a given number of steps. Note that the rotation steps are computed modulo the length of the array, i.e. .
- Find Maximum: Output the maximum element in the array, or output "None" if the array is empty.
Each test case must be processed independently and the results should be printed on separate lines in the order they are processed.
inputFormat
The first line contains an integer T, the number of test cases. For each test case, the first integer is the operation code (op):
• op = 1: Reverse Array • op = 2: Sum Elements • op = 3: Remove Duplicates • op = 4: Rotate Array • op = 5: Find Maximum
If op = 4 (Rotate Array), the next line contains an integer k, representing the number of rotation steps. Then, the next line contains an integer n, the number of elements in the array, followed by a line with n space-separated integers.
For the other operations (1, 2, 3, 5), after the operation code, a line with an integer n is provided, followed by a line with n space-separated integers. Note that if n is 0, then the array is empty.
outputFormat
For each test case, print the result on a new line:
• For operations 1, 3, and 4, output the resulting array as space-separated integers. • For operation 2, output a single integer representing the sum of elements. • For operation 5, output the maximum element if the array is non-empty, or "None" if the array is empty.## sample
1
5
1 2 3 4 5
5 4 3 2 1
</p>