fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define ld long double
  7.  
  8. void Free_palestine() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. cout.tie(NULL);
  12. }
  13.  
  14. const int N = 2e5 + 5;
  15. const int MOD = 1e9 + 7;
  16.  
  17. signed main(){
  18. Free_palestine();
  19. int n; cin>>n;
  20. int arr[n];
  21.  
  22. for(int i = 0; i < n; i++){
  23. cin>>arr[i];
  24. }
  25.  
  26. swap(*min_element(arr, arr+n), *max_element(arr,arr+n));
  27. for(int i = 0; i<n; i++){
  28. cout<<arr[i]<<" ";
  29. }
  30. }
Success #stdin #stdout 0s 5308KB
stdin
5
1 22 4 0 6
stdout
1 0 4 22 6