fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 5;
  5.  
  6. int main() {
  7. int size, mt[MAX_SIZE + 1][MAX_SIZE + 1];
  8. cin >> size;
  9. int lineSum[MAX_SIZE + 1];
  10. for (int line = 1; line <= size; ++line) {
  11. lineSum[line] = 0;
  12. for (int col = 1; col <= size; ++col) {
  13. cin >> mt[line][col];
  14. lineSum[line] += mt[line][col];
  15. }
  16. for (int k = 2; k <= line; ++k) {
  17. if (lineSum[line] < lineSum[k - 1]) {
  18. int aux1 = lineSum[k - 1];
  19. lineSum[k - 1] = lineSum[line];
  20. lineSum[line] = aux1;
  21. for (int col = 1; col <= size; ++col) {
  22. int aux2 = mt[k - 1][col];
  23. mt[k - 1][col] = mt[line][col];
  24. mt[line][col] = aux2;
  25. }
  26. }
  27. }
  28. }
  29. for (int line = 1; line <= size; ++line) {
  30. for (int col = 1; col <= size; ++col) {
  31. cout << mt[line][col] << " ";
  32. }
  33. cout << "\n";
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 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