Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Div2C {
- static int[][] matrix;
- static int n, m;
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- n = sc.nextInt();
- m = sc.nextInt();
- matrix = new int[n][m];
- int q = sc.nextInt();
- sc.nextLine();
- String[] queries = new String[q];
- for (int i = 0; i < q; i++) {
- queries[i] = sc.nextLine();
- }
- for (int i = 0; i < q/2; i++) {
- String tmp = queries[i];
- queries[i] = queries[q-i-1];
- queries[q-i-1] = tmp;
- }
- for (int i = 0; i < q; i++) {
- String[] aa = queries[i].split(" ");
- int t = Integer.parseInt(aa[0]);
- if (t == 1) {
- int r = Integer.parseInt(aa[1])-1;
- shiftrow(r);
- } else if (t == 2) {
- int c = Integer.parseInt(aa[1])-1;
- shiftcol(c);
- } else {
- int r = Integer.parseInt(aa[1])-1;
- int c = Integer.parseInt(aa[2])-1;
- int x = Integer.parseInt(aa[3]);
- matrix[r][c] = x;
- }
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- sb.append(matrix[i][j]);
- if (j != m-1) sb.append(" ");
- }
- sb.append("\n");
- }
- System.out.println(sb.toString());
- sc.close();
- }
- static void shiftrow(int r) {
- int tmp = matrix[r][m-1];
- for (int i = m-1; i > 0; i--) {
- matrix[r][i] = matrix[r][i-1];
- }
- matrix[r][0] = tmp;
- }
- static void shiftcol(int c) {
- int tmp = matrix[n-1][c];
- for (int i = n-1; i > 0; i--) {
- matrix[i][c] = matrix[i-1][c];
- }
- matrix[0][c] = tmp;
- }
- }
Add Comment
Please, Sign In to add comment