CCF CSP 小中大

在这里插入图片描述
在这里插入图片描述

#include 
using namespace std;

#define MAX 100001

int a[MAX];

int main(){
    int n, i = 0, max = 0, min = 0, middle = 0, flag = 0;
    double middle1 = 0;
    memset(a, 0, sizeof(a));
    cin >> n;
    for(i=0; i<n; i++){
        cin >> a[i];
    }

    if(a[0] >= a[1]){
        max = a[0];
        min = a[n-1];
    }
    else if(a[0] <= a[1]){
        max = a[n-1];
        min = a[0];
    }

    if(n % 2 == 0){
        if((a[n/2]%2 == 0 && a[n/2-1]%2) || (a[n/2]%2 && a[n/2-1]%2 == 0)){
            middle1 = (a[n/2] + a[n/2-1])/2.0;
            flag = 1;
        }
        else{
            middle = (a[n/2] + a[n/2-1])/2.0;
        }
    }
    else if(n % 2){
        middle = a[n/2];
    }

    cout << max << " ";
    if(flag){
        cout << setiosflags(ios::fixed) << setprecision(1) << middle1 << " " ;
    }
    else{
        cout << middle << " " ;
    }
    cout << min;
    return 0;
}