Problem 995
Shift 2D Grid
Easy · 10 pts · Matrix, Simulation
Problem
Shift every element of an R × C grid K times. In one shift, each element moves one position to the right; the last element of a row moves to the start of the next row, and the very last element moves to the top-left corner. Print the grid after K shifts. Think of the grid as one long array of R × C elements read row by row: K shifts rotate that array right by K mod (R × C) positions.
Input
The first line contains R, C and K. Each of the next R lines contains C integers.
Output
Print the shifted grid, one row per line.
Constraints
1 <= R, C <= 50; 0 <= K <= 100; -1000 <= values <= 1000
Example input
3 3 1 1 2 3 4 5 6 7 8 9
Example output
9 1 2 3 4 5 6 7 8
Explanation
Shifting 1 2 3 / 4 5 6 / 7 8 9 once moves 9 to the front of the flattened order: 9 1 2 3 4 5 6 7 8, which gives 9 1 2 / 3 4 5 / 6 7 8.