fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. mt19937_64 rd(time(0));
  5. int rand(int L, int R){
  6. return L + rd() % (R - L + 1);
  7. }
  8.  
  9. void random_sort(int* arr, int length){
  10. int pos = rand(0, length - 2);
  11. if(arr[pos] < arr[pos + 1]) swap(arr[pos], arr[pos + 1]);
  12. }
  13.  
  14. bool isSorted(int* arr, int length){
  15. for(int i = 1; i < length; i++){
  16. if(arr[i - 1] < arr[i]) return 0;
  17. }
  18.  
  19. return 1;
  20. }
  21.  
  22. int n, arr[10000];
  23.  
  24. int main(){
  25. ios_base::sync_with_stdio(0);
  26. cin.tie(0); cout.tie(0);
  27.  
  28. cin >> n;
  29. for(int i = 0; i < n; i++) cin >> arr[i];
  30.  
  31. while(!isSorted(arr, n)){
  32. random_sort(arr, n);
  33. }
  34.  
  35. for(int i = 0; i < n; i++) cout << arr[i] << ' ';
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty