#C6996. Array Rotation
Array Rotation
Array Rotation
This problem involves rotating an array by a specified number of steps in a given direction. You are given an integer n representing the number of elements in the array, the array of integers, an integer k indicating the number of steps, and a character that specifies the rotation direction ('L' for left and 'R' for right). Note that an effective rotation is performed by taking k mod n.
Your task is to output the rotated array. Ensure to follow the input and output format exactly.
Mathematically: For left rotation, the new array is given by \[ a = [a_{k+1},a_{k+2},\dots,a_n,a_1,a_2,\dots,a_{k}], \] while for right rotation, it is \[ a = [a_{n-k+1},a_{n-k+2},\dots,a_n,a_1,a_2,\dots,a_{n-k}]. \]
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer n (the number of elements in the array).
- The second line contains n space-separated integers representing the elements of the array.
- The third line contains an integer k (the number of steps to rotate).
- The fourth line contains a single character which is either 'L' or 'R' representing the direction of the rotation.
outputFormat
Output a single line to stdout containing the rotated array. The elements must be printed as space-separated integers.
## sample5
1 2 3 4 5
2
L
3 4 5 1 2
</p>