一、题目描述
二、代码实现
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
long long x1,x2,mid;
cin>>n;
//n是偶数
if(n%2==0)
{
long long x;
for(int i=0;i<n;i++)
{
cin>>x;
if(i==0) x1 = x;
else if(i==n-1) x2 = x;
else if(i==n/2 - 1) mid = x;
else if(i==n/2) mid += x;
else continue;
}
cout<<max(x1,x2)<<" ";
if(mid%2==0) cout<<mid/2<<" ";
//中位数不是整数,保留一位小数
else cout<<fixed<<setprecision(1)<<mid/2.0<<" ";
cout<<min(x1,x2);
}
//n是奇数
else
{
long long x;
for(int i=0;i<n;i++)
{
cin>>x;
if(i==0) x1 = x;
else if(i==n-1) x2 = x;
else if(i==(n+1)/2 - 1) mid = x;
else continue;
}
cout<<max(x1,x2)<<" "<<mid<<" "<<min(x1,x2);
}
return 0;
}