fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main implements Runnable {
  5.  
  6.  
  7. private void solve() throws IOException {
  8.  
  9.  
  10. int T = nextInt();
  11.  
  12. for(int t = 0; t < T; ++t) {
  13.  
  14. int N = nextInt();
  15.  
  16. String line = "";
  17. int[][] matrix = new int[N][N];
  18.  
  19. for(int i = 0; i < N; ++i) {
  20. line = reader.readLine();
  21. for(int j = 0; j < line.length(); ++j) {
  22. matrix[i][j] = line.charAt(j)-'0';
  23. }
  24. }
  25. int M = nextInt();
  26. String action = "";
  27.  
  28. for(int m = 0; m < M; ++m) {
  29.  
  30. action = reader.readLine();
  31. if(action.contains("row")) {
  32.  
  33. int rowA = new Integer(action.split(" ")[1]).intValue();
  34. int rowB = new Integer(action.split(" ")[2]).intValue();
  35.  
  36. for(int col = 0; col < matrix.length; ++col) {
  37. int temp = matrix[rowA][col];
  38. matrix[rowA][col] = matrix[rowB][col];
  39. matrix[rowB][col] = temp;
  40. }
  41.  
  42. } else if(action.contains("col")) {
  43.  
  44. int rowA = new Integer(action.split(" ")[1]).intValue();
  45. int rowB = new Integer(action.split(" ")[2]).intValue();
  46.  
  47. for(int row = 0; row < matrix.length; ++row) {
  48. int temp = matrix[row][rowA];
  49. matrix[rowA][row] = matrix[row][rowB];
  50. matrix[row][rowB] = temp;
  51. }
  52.  
  53.  
  54. } else if(action.equals("inc")) {
  55.  
  56. for(int r = 0; r < matrix.length; ++r) {
  57. for(int c = 0; c < matrix.length; ++c) {
  58. matrix[r][c] = (matrix[r][c] + 1)%10;
  59. }
  60. }
  61.  
  62. } else if(action.equals("dec")) {
  63.  
  64. for(int r = 0; r < matrix.length; ++r) {
  65. for(int c = 0; c < matrix.length; ++c) {
  66. matrix[r][c] = (Math.abs(matrix[r][c] - 1))%10;
  67. }
  68. }
  69.  
  70. } else {
  71.  
  72. int[][] transpose = new int[N][N];
  73. for(int r = 0; r < matrix.length; ++r) {
  74. for(int c = 0; c < matrix.length; ++c) {
  75. transpose[r][c] = matrix[c][r];
  76. }
  77. }
  78. matrix = transpose.clone();
  79.  
  80. }
  81.  
  82.  
  83. }
  84.  
  85. writer.println("Case #"+(t+1));
  86. for(int r = 0; r < matrix.length; ++r) {
  87. for(int c = 0; c < matrix.length; ++c) {
  88. writer.print(matrix[r][c]);
  89. }
  90. writer.println();
  91. }
  92. writer.println();
  93. }
  94.  
  95. }
  96.  
  97. public static void main(String[] args) {
  98. new Main().run();
  99. }
  100.  
  101. StringTokenizer tokenizer;
  102. PrintWriter writer;
  103.  
  104. public void run() {
  105. try {
  106.  
  107. reader = new BufferedReader(new InputStreamReader(System.in)) ;
  108.  
  109.  
  110. tokenizer = null;
  111. writer = new PrintWriter(System.out);
  112.  
  113.  
  114. solve();
  115. reader.close();
  116. writer.close();
  117. } catch (Exception e) {
  118. e.printStackTrace();
  119. System.exit(1);
  120. }
  121. }
  122.  
  123. int nextInt() throws IOException {
  124. return Integer.parseInt(nextToken());
  125. }
  126.  
  127. long nextLong() throws IOException {
  128. return Long.parseLong(nextToken());
  129. }
  130.  
  131. double nextDouble() throws IOException {
  132. return Double.parseDouble(nextToken());
  133. }
  134.  
  135. String nextToken() throws IOException {
  136. while(tokenizer == null || !tokenizer.hasMoreTokens()) {
  137. tokenizer = new StringTokenizer(reader.readLine());
  138. }
  139.  
  140. return tokenizer.nextToken();
  141. }
  142. }
Runtime error #stdin #stdout 0.03s 245632KB
stdin
2
4
1234
5678
1234
5678
1
transpose
3
000
111
000
2
row 1 2
inc
stdout
Standard output is empty