fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 10;
  5.  
  6. int main() {
  7. int n, m, mt[MAX_SIZE + 1][MAX_SIZE + 1], arr[MAX_SIZE + 1];
  8. //pentru optimizare cu fara mt, in loc de mt[][]-> currentElem;
  9. cin >> n >> m;
  10. int arrIndex = 1;
  11. for(int i = 1; i <= n; ++i) {
  12. int sum = 0;
  13. for(int j = 1; j <= m; ++j) {
  14. cin >> mt[i][j];
  15. sum += mt[i][j];
  16. }
  17. arr[arrIndex++] = sum;//arr[i] = sum;
  18. }
  19. for(int i = 1; i < n ; ++i) {
  20. for(int j = i + 1; j <= n ; ++j) {
  21. if(arr[i] < arr[j]) {
  22. swap(arr[i], arr[j]);
  23. /*int temp;//de creat intre cele 2 for-uri casa se creeze
  24. deodata cu for-ul si sa se stinga cu el pentru a nu tot
  25. aloca si dealoca memoria
  26. if (v[i] < v[j]) {
  27. temp = v[i];
  28. v[i] = v[j];
  29. v[j] = temp;
  30. }*/
  31. }
  32. }
  33. }
  34. for(int i = 1; i <= n; ++i) {
  35. cout << arr[i] << " ";
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 5292KB
stdin
3 3
9 2 6
6 1 4
6 3 4
stdout
17 13 11