【题目描述】
导游往往喜欢从所带的旅游团中选一个身高最高的游客,站在旅游团的前面帮着拿旅行社的旗积。现在给定n个游客的身高(均为正整数)将身高最高的游客(如果身高最高的游客不唯一,那么选择最前面的那一个)和第一个游客调换位置,再依次输出他们的身高。
【输入】
第一行一个正整数n,1≤ns10000表示有n个游客。
第二行包含n个正整数,之间用一个空格隔开,表示n个游客的身高。
【输出】
一行n个正整数,每两个数之间用一个空格隔开,表示调换位置后各个位置上游客的身高。
【输入样例】
6
160 155 170 175 172 164
【输出样例】
175 155 170 160 172 164
代码
#include<bits/stdc++.h>
using namespace std;
int a[10001],n,s,t,q;
int main()
{
cin>>n>>a[1];
s=a[1];
for(int i=2;i<=n;i++)
{
cin>>a[i];
if(a[i]>s)
{
s=a[i];
t=i;
}
}
q=a[t];
a[t]=a[1];
a[1]=q;
for(int i=1;i<=n;i++)
printf("%d ",a[i]);
return 0;
}