fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define name "SORT"
  5. const int MAXN = 2e5+5;
  6. int n, a[MAXN];
  7.  
  8. void setIO(){
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0); cout.tie(0);
  11. if (fopen(name".inp", "r")){
  12. freopen(name".inp", "r", stdin);
  13. freopen(name".out", "w", stdout);
  14. }
  15. }
  16.  
  17. int main(){
  18. setIO(); // Nhập xuất file
  19. cin >> n;
  20. for (int i = 0; i<n; i++) cin >> a[i];
  21.  
  22. // Sắp xếp tăng dần
  23. sort(a, a+n);
  24. for (int i = 0; i<n; i++) cout << a[i] << " ";
  25. cout << "\n";
  26.  
  27. // Sắp xếp giảm dần
  28. sort(a, a+n, greater<int>());
  29. for (int i = 0; i<n; i++) cout << a[i] << " ";
  30. }
Success #stdin #stdout 0s 5320KB
stdin
10
9 3 4 5 7 6 8 10 2 1
stdout
1 2 3 4 5 6 7 8 9 10 
10 9 8 7 6 5 4 3 2 1