fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 5;
  5. const int MAX_VALUE = 10;
  6. int sumFreq[MAX_SIZE * MAX_VALUE + 1];
  7.  
  8. int main() {
  9. int size, mt[MAX_SIZE + 1][MAX_SIZE + 1];
  10. cin >> size;
  11. for (int line = 1; line <= size; ++line) {
  12. mt[line][0] = 0;
  13. for (int col = 1; col <= size; ++col) {
  14. cin >> mt[line][col];
  15. mt[line][0] += mt[line][col];
  16. }
  17. ++sumFreq[mt[line][0]];
  18. }
  19. int nextLinePos = 0;
  20. for (int i = 0; i <= size * MAX_VALUE; ++i) {
  21. if (sumFreq[i] == 1) {
  22. ++nextLinePos;
  23. for (int line = nextLinePos; line <= size; ++line) {
  24. if (i == mt[line][0]) {
  25. if (line != nextLinePos) {
  26. for (int col = 0; col <= size; ++col) {
  27. int aux = mt[nextLinePos][col];
  28. mt[nextLinePos][col] = mt[line][col];
  29. mt[line][col] = aux;
  30. }
  31. }
  32. for (int col = 1; col <= size; ++col) {
  33. cout << mt[nextLinePos][col] << " ";
  34. }
  35. line = size + 1;
  36. cout << "\n";
  37. }
  38. }
  39. }
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
9 8 7 6 5
8 7 6 5 4
7 6 5 4 3
6 5 4 3 2
5 4 3 2 1
	 
5 4 3 2 1
6 5 4 3 2
7 6 5 4 3
8 7 6 5 4
9 8 7 6 5
stdout
5 4 3 2 1 
6 5 4 3 2 
7 6 5 4 3 
8 7 6 5 4 
9 8 7 6 5