Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std ;
- typedef long long ll ;
- int main() {
- ios::sync_with_stdio(false) ; cout.tie(NULL) ; cin.tie(NULL) ;
- int n ; cin >> n ;
- int minidx , maxidx ;
- int arr[n] ;
- for (int i = 0; i < n; i++) cin >> arr[i] ;
- int max = arr[0] ;
- int min = arr[0] ;
- for (int i = 0; i < n; i++) {
- if (arr[i] < min) {
- min = arr[i] , minidx = i ;
- }
- if (arr[i] > max) {
- max = arr[i] , maxidx = i ;
- }
- }
- swap(arr[minidx] , arr[maxidx]) ;
- for (int i = 0; i < n; i++) cout << arr[i] << " " ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment