fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Matrix
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. int n = in.nextInt();
  11. double[][] a = new double[n][n], aa = new double[n][n], result1 = new double[n][n], result2 = new double[n][n];
  12. for (int i = 0; i < a.length; i++)
  13. {
  14. for (int j = 0; j < a[i].length; j++)
  15. {
  16. a[i][j] = in.nextDouble();
  17. aa[j][i] = a[i][j];
  18. }
  19. }
  20. for (int i = 0; i < a.length; i ++)
  21. {
  22. for (int j = 0; j < a[i].length; j ++)
  23. {
  24. result1[i][j] = 0.5 * (a[i][j] + aa[i][j]);
  25. result2[i][j] = 0.5 * (a[i][j] - aa[i][j]);
  26. }
  27. }
  28. for (int i = 0; i < a.length; i++)
  29. {
  30. for (int j = 0; j < a[i].length; j++)
  31. {
  32. System.out.print(result1[i][j] + " ");
  33. }
  34. System.out.println(' ');
  35. }
  36. System.out.println(' ');
  37. for (int i = 0; i < a.length; i ++)
  38. {
  39. for (int j = 0; j < a[i].length; j ++)
  40. {
  41. System.out.print(result2[i][j] + " ");
  42. }
  43. System.out.println(' ');
  44. }
  45. }
  46. }
Success #stdin #stdout 0.18s 321344KB
stdin
3
1 2 3
2 4 6
1 4 8
stdout
1.0 2.0 2.0  
2.0 4.0 5.0  
2.0 5.0 8.0  
 
0.0 0.0 1.0  
0.0 0.0 1.0  
-1.0 -1.0 0.0