fork download
  1. #include <iostream>
  2. #define M 3
  3. #define N 3
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int getnumberofpositive(int argc,int x[])
  9. {
  10. int count = 0;
  11. for(int i = 0; i < argc; i++)
  12. if (x[i] > 0)
  13. count++;
  14. return count;
  15. }
  16.  
  17. int main()
  18. {
  19. int a[M][N] = {{-1,-2,3},{4,-5,6},{7,8,9}};
  20. cout << "Inputed array:" <<endl;
  21. for (int i = 0; i < M; i++)
  22. {
  23. for (int j = 0; j < N; j++)
  24. cout << a[i][j] << " ";
  25. cout << endl;
  26. }
  27. int vector[M];
  28. for (int i = 0; i < M; i++)
  29. vector[i] = getnumberofpositive(N, a[i]);
  30. int flag = 1;
  31. while (flag)
  32. {
  33. flag = 0;
  34. for (int i = 1; i < M; ++i) {
  35. if (vector[i] > vector[i-1])
  36. {
  37. flag = 1;
  38. swap(vector[i], vector[i-1]);
  39. swap(a[i],a[i-1]);
  40. }
  41. }
  42. }
  43. cout << endl << "new array:" <<endl;
  44. for (int i = 0; i < M; i++)
  45. {
  46. for (int j = 0; j < N; j++)
  47. cout << a[i][j] << " ";
  48. cout << endl;
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
Inputed array:
-1 -2 3 
4 -5 6 
7 8 9 

new array:
7 8 9 
4 -5 6 
-1 -2 3