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 bozo_sort(int* arr, int lenght){
  10. int L = rand(0, lenght - 1);
  11. int R = rand(0, lenght - 1);
  12. if(R < R) swap(L, R);
  13.  
  14. if(arr[L] < arr[R]) swap(arr[L], arr[R]);
  15. }
  16.  
  17. bool isSorted(int* arr, int length){
  18. for(int i = 1; i < length; i++){
  19. if(arr[i - 1] < arr[i]) return 0;
  20. }
  21.  
  22. return 1;
  23. }
  24.  
  25. int n, arr[10000];
  26.  
  27. int main(){
  28. ios_base::sync_with_stdio(0);
  29. cin.tie(0); cout.tie(0);
  30.  
  31. cin >> n;
  32. for(int i = 0; i < n; i++) cin >> arr[i];
  33.  
  34. while(!isSorted(arr, n)){
  35. bozo_sort(arr, n);
  36. }
  37.  
  38. for(int i = 0; i < n; i++) cout << arr[i] << ' ';
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty