CCF CSP 小中大

©2015-2019 Wang Liguang. All Rights Reserved.本文为博主原创文章,未经博主允许不得以任何形式转载,否则将会追究您的法律责任。您阅读本文即表示您已经同意了本站声明(详见置顶文章)!本文仅供参考,请您自行甄别有效性,出现任何问题,博主不承担任何责任!
本文链接: https://blog.csdn.net/happywlg123/article/details/98962753

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

#include <bits/stdc++.h>
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;
}

猜你喜欢

转载自blog.csdn.net/happywlg123/article/details/98962753