Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. package ya;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class GoldenRotations {
  6.  
  7. public static void main(String[] args) throws IOException {
  8. int N=readInt();
  9.  
  10. int arr[][]=new int [N][N];
  11.  
  12. for(int i=0; i<N;i++) {
  13. for(int j=0;j<N;j++) {
  14. arr[i][j]=readInt();
  15. }
  16. }
  17. int M = readInt()%4;
  18.  
  19. if(M==0) {
  20. for(int i=0; i<N;i++) {
  21. for(int j=0;j<N;j++) {
  22. System.out.print(arr[i][j]+" ");
  23. }
  24. System.out.println();
  25. }
  26.  
  27. }
  28. if(M==1) {
  29. for(int i=N;i>0;i--) {
  30. for(int j=0;j<N;j++) {
  31. System.out.print(arr[N-j][N-i]+" ");
  32. }
  33. System.out.println();
  34. }
  35. }
  36.  
  37.  
  38. if(M==2) {
  39. for(int i=1;i<=N;i++) {
  40. for(int j=1;j<=N;j++ ) {
  41. System.out.print(arr[N-i][N-j]+" ");
  42. }
  43. System.out.println();
  44. }
  45. }
  46. if(M==3) {
  47. for(int i=1;i<=N;i++) {
  48. for(int j=N;j>0;j-- ) {
  49. System.out.print(arr[N-j][N-i]+" ");
  50. }
  51. System.out.println();
  52. }
  53. }
  54. }
  55. final private static int BUFFER_SIZE = 1 << 16;
  56. private static DataInputStream din = new DataInputStream(System.in);
  57. private static byte[] buffer = new byte[BUFFER_SIZE];
  58. private static int bufferPointer = 0, bytesRead = 0;
  59. static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  60.  
  61. public static String readLine() throws IOException {
  62. byte[] buf = new byte[64]; // line length
  63. int cnt = 0, c;
  64. while ((c = Read()) != -1) {
  65. if (c == '\n')
  66. break;
  67. buf[cnt++] = (byte) c;
  68. }
  69. return new String(buf, 0, cnt);
  70. }
  71.  
  72. public static String read() throws IOException {
  73. byte[] ret = new byte[1024];
  74. int idx = 0;
  75. byte c = Read();
  76. while (c <= ' ') {
  77. c = Read();
  78. }
  79. do {
  80. ret[idx++] = c;
  81. c = Read();
  82. } while (c != -1 && c != ' ' && c != '\n' && c != '\r');
  83. return new String(ret, 0, idx);
  84. }
  85.  
  86. public static int readInt() throws IOException {
  87. int ret = 0;
  88. byte c = Read();
  89. while (c <= ' ')
  90. c = Read();
  91. boolean neg = (c == '-');
  92. if (neg)
  93. c = Read();
  94. do {
  95. ret = ret * 10 + c - '0';
  96. } while ((c = Read()) >= '0' && c <= '9');
  97.  
  98. if (neg)
  99. return -ret;
  100. return ret;
  101. }
  102.  
  103. public static long readLong() throws IOException {
  104. long ret = 0;
  105. byte c = Read();
  106. while (c <= ' ')
  107. c = Read();
  108. boolean neg = (c == '-');
  109. if (neg)
  110. c = Read();
  111. do {
  112. ret = ret * 10 + c - '0';
  113. } while ((c = Read()) >= '0' && c <= '9');
  114. if (neg)
  115. return -ret;
  116. return ret;
  117. }
  118.  
  119. public static double readDouble() throws IOException {
  120. double ret = 0, div = 1;
  121. byte c = Read();
  122. while (c <= ' ')
  123. c = Read();
  124. boolean neg = (c == '-');
  125. if (neg)
  126. c = Read();
  127.  
  128. do {
  129. ret = ret * 10 + c - '0';
  130. } while ((c = Read()) >= '0' && c <= '9');
  131.  
  132. if (c == '.') {
  133. while ((c = Read()) >= '0' && c <= '9') {
  134. ret += (c - '0') / (div *= 10);
  135. }
  136. }
  137.  
  138. if (neg)
  139. return -ret;
  140. return ret;
  141. }
  142.  
  143. private static void fillBuffer() throws IOException {
  144. bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  145. if (bytesRead == -1)
  146. buffer[0] = -1;
  147. }
  148.  
  149. private static byte Read() throws IOException {
  150. if (bufferPointer == bytesRead)
  151. fillBuffer();
  152. return buffer[bufferPointer++];
  153. }
  154.  
  155. public void close() throws IOException {
  156. if (din == null)
  157. return;
  158. din.close();
  159. }
  160.  
  161. static void print(Object o) {
  162. pr.print(o);
  163. }
  164.  
  165. static void println(Object o) {
  166. pr.println(o);
  167. }
  168.  
  169. static void flush() {
  170. pr.flush();
  171. }
  172.  
  173. static void println() {
  174. pr.println();
  175. }
  176.  
  177. static void exit() throws IOException {
  178. din.close();
  179. pr.close();
  180. System.exit(0);
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement