a53

SortMatrixLin

a53
Mar 8th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. bool cmp(int a,int b)
  6. {
  7. if(a<b)
  8. return false;
  9. return true;
  10. }
  11.  
  12. int main()
  13. {
  14. int n,m;
  15. char c;
  16. cin>>n>>m;
  17. cin>>c;
  18. int a[n*m+1];
  19. for(int i=1;i<=n*m;++i)
  20. cin>>a[i];
  21. if(c=='+')
  22. sort(a+1,a+n*m+1);
  23. else
  24. sort(a+1,a+n*m+1,cmp);
  25. for(int i=1;i<=n*m;++i)
  26. {
  27. cout<<a[i]<<' ';
  28. if(i%m==0)
  29. cout<<'\n';
  30. }
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment