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

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
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