西电复试之——CCF201903-01 小中大

西电复试之——CCF201903-01 小中大

在这里插入图片描述

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 101000;
int a[maxn] = { 0 };
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n - 1] << " ";
	if (n % 2 == 0) {
		if ((a[n / 2 - 1] + a[n / 2]) % 2 == 1) {
			printf("%.1lf ", (double)((a[n / 2 - 1] + a[n / 2]) / 2.0));
		}
		else
		{
			cout << (a[n / 2 - 1] + a[n / 2]) / 2 << " ";
		}

	}
	else
	{
		cout << a[n / 2] << " ";
	}
	cout << a[0];
	return 0;
}

双精度和小数点问题

double双精度 输出%.1lf

原创文章 35 获赞 17 访问量 1277

猜你喜欢

转载自blog.csdn.net/qq_41436493/article/details/105623469
今日推荐