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. for (int line = 1; line <= size; ++line) {
  10. mt[line][0] = 0;
  11. for (int col = 1; col <= size; ++col) {
  12. cin >> mt[line][col];
  13. mt[line][0] += mt[line][col];
  14. }
  15. for (int k = 2; k <= line; ++k) {
  16. if (mt[line][0] < mt[k - 1][0]) {
  17. for (int col = 0; col <= size; ++col) {
  18. int aux = mt[k - 1][col];
  19. mt[k - 1][col] = mt[line][col];
  20. mt[line][col] = aux;
  21. }
  22. }
  23. }
  24. }
  25. for (int line = 1; line <= size; ++line) {
  26. for (int col = 1; col <= size; ++col) {
  27. cout << mt[line][col] << " ";
  28. }
  29. cout << "\n";
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 5288KB
stdin
5
1 2 3 4 5
9 1 2 3 4
8 9 1 2 3
7 8 9 1 2
6 7 8 9 1
	 
1 2 3 4 5
9 1 2 3 4
8 9 1 2 3
7 8 9 1 2
6 7 8 9 1
stdout
1 2 3 4 5 
9 1 2 3 4 
8 9 1 2 3 
7 8 9 1 2 
6 7 8 9 1