题目描述:
c/c++代码(only95分)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <iterator>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int PI = acos(-1);
const int E = exp(1);
const int MOD = 1e9+7;
const int MAX = 1e5+5;
int n;
int a[MAX];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while(cin >> n)
{
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
int _max,_min;
double _mid;
_max = max(a[0],a[n-1]);
_min = min(a[0],a[n-1]);
if(n % 2 == 0)
{
_mid = (a[n/2]+a[(n/2)-1]) / 2.0;
if((a[n/2]+a[(n/2)-1]) % 2 == 0)
{
cout << _max << " " << (int)_mid << " " << _min << endl;
}
else
{
// 要求四舍五入保留小数位,直接用%f,或者(int)((_mid*10)+0.5)/10.0
//printf("%d %0.1f %d\n",_max,_mid,_min);
printf("%d %0.1f %d\n",_max,(int)((_mid*10)+0.5)/10.0,_min);
}
}
else
{
_mid = a[n/2];
// 中间的mid必须加一个(int)才能100分,否则只有95分,
// 因为确实输入的n个数就是整数,但是赋给的_mid是一个double,输出默认还是带小数点的。
cout << _max << " " << (int)_mid << " " << _min << endl;
}
}
return 0;
}