fork(1) download
  1.  
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Test
  7. {
  8.  
  9. public static void display(int[][] p,int q){
  10. for(int i=0;i<q;i++){
  11. for(int j=0;j<q;j++){
  12. System.out.print(" "+p[i][j]);
  13. }
  14. System.out.println();
  15. }
  16. }
  17. public static void rot_90(int[][] p,int q){
  18. int[][] r=new int[q][q] ;
  19. for(int i=0;i<q;i++){
  20. for(int j=0;j<q;j++){
  21. r[i][j] = p[q-j-1][i] ;
  22. display(r,q);
  23. }
  24. }
  25.  
  26. }
  27. public static void rot_180(int[][] p,int q){
  28. rot_90(p,q);
  29. rot_90(p,q);
  30. display(p,q);
  31. }
  32. public static void main (String[] args) throws java.lang.Exception
  33. {
  34. Scanner in = new Scanner(System.in);
  35. int a = in.nextInt() ;
  36. int[][] b = new int[a][a] ;
  37. for(int i=0;i<a; i++){
  38. for(int j=0;j<a; j++){
  39. b[i][j] = in.nextInt();
  40. }
  41. }
  42. rot_90(b,a);
  43. display(b,a) ;
  44. System.out.println();
  45. rot_180(b,a) ;
  46. display(b,a);
  47.  
  48. }
  49. }
Success #stdin #stdout 0.15s 41992KB
stdin
3
1 2 3
2 3 1
3 2 1
stdout
 3 0 0
 0 0 0
 0 0 0
 3 2 0
 0 0 0
 0 0 0
 3 2 1
 0 0 0
 0 0 0
 3 2 1
 2 0 0
 0 0 0
 3 2 1
 2 3 0
 0 0 0
 3 2 1
 2 3 2
 0 0 0
 3 2 1
 2 3 2
 1 0 0
 3 2 1
 2 3 2
 1 1 0
 3 2 1
 2 3 2
 1 1 3
 1 2 3
 2 3 1
 3 2 1

 3 0 0
 0 0 0
 0 0 0
 3 2 0
 0 0 0
 0 0 0
 3 2 1
 0 0 0
 0 0 0
 3 2 1
 2 0 0
 0 0 0
 3 2 1
 2 3 0
 0 0 0
 3 2 1
 2 3 2
 0 0 0
 3 2 1
 2 3 2
 1 0 0
 3 2 1
 2 3 2
 1 1 0
 3 2 1
 2 3 2
 1 1 3
 3 0 0
 0 0 0
 0 0 0
 3 2 0
 0 0 0
 0 0 0
 3 2 1
 0 0 0
 0 0 0
 3 2 1
 2 0 0
 0 0 0
 3 2 1
 2 3 0
 0 0 0
 3 2 1
 2 3 2
 0 0 0
 3 2 1
 2 3 2
 1 0 0
 3 2 1
 2 3 2
 1 1 0
 3 2 1
 2 3 2
 1 1 3
 1 2 3
 2 3 1
 3 2 1
 1 2 3
 2 3 1
 3 2 1