fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8.  
  9. unsigned int n;
  10. cin >> n;
  11.  
  12. vector <int> a(n);
  13.  
  14. for (int i = 0; i < n; i++) {
  15. cin >> a[i];
  16. }
  17.  
  18. for (int i = 0; i < n; i++) {
  19. int max = 0;
  20. int max_value = a[max];
  21.  
  22. for (int j = 0; j < n - i; j++) {
  23. // cout << a[j] << " ";
  24. if (a[j] > max_value) {
  25. max = j;
  26. max_value = a[j];
  27. }
  28.  
  29.  
  30. }
  31.  
  32. swap(a[max], a[n - i - 1]);
  33. cout << max << " ";
  34. }
  35.  
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 5324KB
stdin
3
1 2 3
stdout
2 1 0