#include<stdio.h> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; int main(){ int n; int a[100000]; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d", &a[i]); } int max=a[0]; int min=a[0]; for(int i=0;i<n;i++){ if(a[i]>max){ max=a[i]; } if(a[i]<min){ min=a[i]; } } for(int i=0;i<n;i++){ if(a[i]==max){ int temp=a[i]; a[i]=a[n-1]; a[n-1]=temp; } if(a[i]==min){ int temp=a[i]; a[i]=a[0]; a[0]=temp; } } for(int i=0;i<n;i++){ if(i==0) printf("%d",a[i]); else printf(" %d",a[i]); } return 0; } |
Double click to view unformatted code.