CSP201903-1 小中大

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int minn, maxx;
    if (n % 2) {
        int mid;
        for (int i = 1; i <= n; i++) {
            int x;
            cin >> x;
            if (i == 1) minn = x;
            if (i == n) maxx = x;
            if (i == n / 2 + 1) mid = x;
        }
        if (minn > maxx) swap(minn, maxx);
        cout << maxx << ' ' << mid << ' ' << minn << endl;
    }
    else {
        int mid = 0;
        for (int i = 1; i <= n; i++) {
            int x;
            cin >> x;
            if (i == 1) minn = x;
            if (i == n) maxx = x;
            if (i == n / 2 || i == n / 2 + 1) mid += x;
        }
        if (minn > maxx) swap(minn, maxx);
        if (mid % 2 == 0) {
            mid /= 2;
            cout << maxx << ' ' << mid << ' ' << minn << endl;
        }
        else {
            double midd = mid / 2.0;
            printf("%d %.1lf %d\n", maxx, midd, minn);
        }
    }
    return 0;
}

 

猜你喜欢

转载自www.cnblogs.com/AntonLiu/p/11985738.html