http://ac.jobdu.com/problem.php?pid=1053
#include<stdio.h>
#include<string.h>#include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
int i,n,a[1000],b[1000];
while(scanf("%d",&n)!=EOF){
memset(b,0,sizeof(b));
for(i=0;i<n;i++){
scanf("%d",&a[i]);
b[i]=a[i];
}
qsort(a,n,sizeof(int),cmp);
for(i=0;i<n;i++){
if(i!=0) printf(" ");
if(b[i]==a[0]) printf("%d",a[n-1]);
else if(b[i]==a[n-1]) printf("%d",a[0]);
else printf("%d",b[i]);
}
printf("\n");
}
return 0;
}