HDOJ 2014

青年歌手大奖赛_评委会打分

Problem Description
青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分。

Input
输入数据有多组,每组占一行,每行的第一个数是n(2<n<=100),表示评委的人数,然后是n个评委的打分。

Output
对于每组输入数据,输出选手的得分,结果保留2位小数,每组输出占一行。

Sample Input
3 99 98 97
4 100 99 98 97

Sample Output
98.00
98.50

Author
lcy

Source
C语言程序设计练习(三)

解题思路
用数组储存数据,使用sort()函数进行排序,然后求平均值。注意小数。

AC

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[105], n;
	double ans;
	while (cin >> n) {
		ans = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		for (int i = 1; i < n - 1; i++) {
			ans += a[i];
		}
		printf("%.2lf\n", ans / (n - 2));
	}
	return 0;
}

2024.02.29

#include<stdio.h>
#include<stdlib.h>
using namespace std;
int cmp(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
int main() {
	int n;
	int score[105];
	float ans;
	while (scanf("%d", &n) != EOF) {
		ans = 0.;
		for (int i = 0; i < n; i++) {
			scanf("%d", &score[i]);
		}
		qsort(score, n, sizeof(score[0]), cmp);
		for (int i = 1; i < n - 1; i++)
			ans += score[i];
		printf("%.2f\n", ans / (n - 2));
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值