试题编号:201903-1
试题名称:小中大
时间限制:1.0s
内存限制:512.0MB
思路:题目很简单,依次输出最大值,中位数,最小值。输出中位数的时候很神奇的出错。。。费了好半天事才改对。
#include<iostream>
#include<algorithm>
using namespace std;
const int maxx=1000010;
int n,mid,a[maxx];
int main()
{cin>>n;for(int i=1;i<=n;i++)cin>>a[i];sort(a+1,a+n+1);if(n%2==0){mid=a[n/2]+a[n/2+1];if(mid%2!=0)cout<<a[n]<<" "<<mid/2<<".5"<<" "<<a[1];elsecout<<a[n]<<" "<<mid/2<<" "<<a[1];}else {mid=a[n/2+1];cout<<a[n]<<" "<<mid<<" "<<a[1];}return 0;
}