#K12206. Rotate Marbles
Rotate Marbles
Rotate Marbles
In this problem, you are given a list of integers representing the colors of marbles and an integer (R) that indicates the number of rotations to perform. If (R) is positive, rotate the list to the right (clockwise) by (R) positions; if (R) is negative, rotate the list to the left (counter-clockwise) by (|R|) positions.
The effective rotation is computed as (R \mod N), where (N) is the number of marbles. Your task is to output the rearranged list after performing the rotation for each test case provided.
inputFormat
The input begins with an integer (T) indicating the number of test cases. For each test case, there are three lines:
1. An integer (N) representing the number of marbles.
2. (N) space-separated integers representing the initial arrangement of marbles.
3. An integer (R) representing the number of rotations to perform.
outputFormat
For each test case, output a single line containing (N) space-separated integers representing the final arrangement of marbles after performing the rotations.## sample
3
5
1 2 3 4 5
2
6
10 20 30 40 50 60
-3
5
1 2 3 4 5
-2
4 5 1 2 3
40 50 60 10 20 30
3 4 5 1 2
</p>