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