Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl '\n'
  4. #define ll long long
  5. int a[3][3];
  6. int suma()
  7. {
  8. for(int i=0;i<3;i++)
  9. {
  10. if(a[i][0]!=0 && a[i][1]!=0 && a[i][2]!=0)
  11. {
  12. return a[i][0]+a[i][1]+a[i][2];
  13. }
  14. if(a[0][i]!=0 && a[1][i]!=0 && a[2][i]!=0)
  15. {
  16. return a[0][i]+a[1][i]+a[2][i];
  17. }
  18. }
  19. if(a[0][0]!=0 && a[1][1]!=0 && a[2][2]!=0)
  20. {
  21. return a[0][0]+a[1][1]+a[2][2];
  22. }
  23. else
  24. return a[2][0]+a[1][1]+a[0][2];
  25. }
  26. int main()
  27. {
  28. ios_base::sync_with_stdio(false);
  29. freopen("input.test992","r",stdin);
  30. freopen("output.test992","w",stdout);
  31. cin.tie(0);
  32. for(int i=0;i<3;i++)
  33. {
  34. for(int j=0;j<3;j++)
  35. {
  36. cin >> a[i][j];
  37. }
  38. }
  39. if((a[0][0]==0 && a[1][1]==0 && a[2][2]==0) || (a[0][2]==0 && a[1][1]==0 && a[2][0]==0))
  40. {
  41. bool test=false;
  42. if(a[0][2]==0)
  43. {
  44. for(int i=0;i<3;i++)
  45. {
  46. swap(a[i][0],a[i][2]);
  47. }
  48. test=true;
  49. }
  50. a[0][0]=(a[2][0]+2*a[2][1]-a[0][2])/2;
  51. a[1][1]=(a[0][2]+a[2][0])/2;
  52. a[2][2]=(2*a[0][1]+a[0][2]-a[2][0])/2;
  53. if(test)
  54. {
  55. for(int i=0;i<3;i++)
  56. {
  57. swap(a[i][0],a[i][2]);
  58. }
  59. }
  60. }
  61. else
  62. {
  63. int sum=suma();
  64. for(int i=0;i<3;i++)
  65. {
  66. if(a[i][0]==0 && a[i][1]!=0 && a[i][2]!=0)
  67. {
  68. a[i][0]=sum-(a[i][1]+a[i][2]);
  69. }
  70. else if(a[i][0]!=0 && a[i][1]==0 && a[i][2]!=0)
  71. {
  72. a[i][1]=sum-(a[i][0]+a[i][2]);
  73. }
  74. else if(a[i][0]!=0 && a[i][1]!=0 && a[i][2]==0)
  75. {
  76. a[i][2]=sum-(a[i][0]+a[i][1]);
  77. }
  78. }
  79. for(int i=0;i<3;i++)
  80. {
  81. if(a[0][i]==0 && a[1][i]!=0 && a[2][i]!=0)
  82. {
  83. a[0][i]=sum-(a[1][i]+a[2][i]);
  84. }
  85. else if(a[0][i]!=0 && a[1][i]==0 && a[2][i]!=0)
  86. {
  87. a[1][i]=sum-(a[0][i]+a[2][i]);
  88. }
  89. else if(a[0][i]!=0 && a[1][i]!=0 && a[2][i]==0)
  90. {
  91. a[2][i]=sum-(a[0][i]+a[1][i]);
  92. }
  93. }
  94. }
  95. for(int i=0;i<3;i++)
  96. {
  97. for(int j=0;j<3;j++)
  98. {
  99. cout << a[i][j] << " ";
  100. }
  101. cout << endl;
  102. }
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement