首页 > 试题广场 >

英文金曲大赛

[编程题]英文金曲大赛
  • 热度指数:431 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
nowcoder 在大一的时候参加过工商学院的“英语聚乐部”。告诉你个秘密,这个俱乐部是个好地方,不但活动精彩而且有MM。 这不,英语俱乐部举办了一个叫做“英文金曲大赛”的节目。这个节目有好多人参加,这不,成绩出来了,nowcoder 当是很勇敢,自告奋勇接下了算出大家的总得分的任务。 当时有7个评委,每个评委都要给选手打分,现在要求去掉一个最高分和去掉一个最低分,再算出平均分。结果精确到小数点后两位。

输入描述:
测试数据包括多个实例。 每组数据包括7个实数,代表评委们对该选手的评分。紧接着是选手的名字,名字的长度不超过30个字符。 输入直到文件结束。


输出描述:
算出每位选手名字和最终得分,结果保留两位有效数字(四舍五入)。
示例1

输入

10 10 10 10 10 10 9 redraiment
0 0 0 0 0 0 0 beast

输出

redraiment 10.00
beast 0.00
依次读入数据,同时求和,读入过程中更新最大最小值,然后读完7个数,最后减去最大最小并求平均。
发表于 2015-11-02 21:37:02 回复(0)
更多回答
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>

using namespace std;

int main()
{
	//freopen("in.txt", "r", stdin);
	vector<double> grade(7);
	string name;
	while (cin >> grade[0])
	{
		for (int i = 1; i < 7; ++i) cin >> grade[i];
		cin >> name;
		sort(grade.begin(), grade.end());
		double sum = 0;
		for (int i = 1; i <= 5; ++i) sum += grade[i];
		cout << name << " " << fixed << setprecision(2) << sum / 5 << endl;
	}
}
 

发表于 2017-07-15 18:22:24 回复(0)

python solution

import sys

for i in sys.stdin.readlines():
    arr = i.strip().split()
    scores = list(map(float, arr[:-1]))
    print(arr[-1], "{0:.2f}".format((sum(scores) - min(scores) - max(scores)) / (len(scores) - 2)))
发表于 2017-11-16 14:17:07 回复(0)
/*
	我的QQ:825580813(欢迎来一起讨论,刷题,PK)。
	这道题呢就是一个排序,掐头去尾就好,所以就不多说啦哈。^_*
*/
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;


int main ()
{
	ios::sync_with_stdio(false);	//关闭cin的同步功能,增加运行效率
	double aggregateScore = 0, score, minScore, maxScore;
	while( cin >> score )
	{		
		aggregateScore = maxScore = minScore = score;
		for( int i = 1; i < 7; i++ )
		{
			cin >> score;
			aggregateScore += score;
			maxScore = score > maxScore ? score : maxScore;
			minScore = score < minScore ? score : minScore;
		}
		string name;
		cin >> name;
		cout << name << " ";
		printf ("%.2lf\n", (aggregateScore - minScore - maxScore) / 5);
	}
	return 0;
}

这段代码有哪里错吗?

发表于 2016-10-24 18:19:59 回复(0)
#include <bits/stdc++.h>

int main(int argc, char const *argv[]) {
    float score, maxScore, minScore, sum;
    char name[30];
    while (scanf("%f", &score) != EOF) {
        sum = minScore = maxScore = score;
        for (int i = 1; i < 7; ++i) {
            scanf("%f", &score);
            sum += score;
            maxScore = score > maxScore ? score : maxScore;
            minScore = score < minScore ? score : minScore;
        }
        scanf("%s", name);
        printf("%s %.2f\n", name, (sum - maxScore - minScore) / 5);
    }
    return 0;
}

发表于 2018-03-02 14:56:23 回复(0)
// write your code here cpp
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
    vector<double> score(7);
    while(cin>>score[0])
    {
        for(int i=1;i<7;++i)
            cin>>score[i];
        string name;
        cin>>name;
        sort(score.begin(),score.end());
        double sum=0;
        for(int i=1;i<=5;++i)
            sum+=score[i];
        cout<<name<<" "<<fixed<<setprecision(2)<<sum/5<<endl;
    }
    return 0;
}

发表于 2017-10-27 11:39:05 回复(0)
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	double num;
	while (cin >> num)
	{
		vector<double> data;
		data.push_back(num);
		for (int i = 0; i < 6; i++)
		{
			cin >> num;
			data.push_back(num);
		}
		cin >> s;
		sort(data.begin(), data.end());
		double count = 0.0;
		for (int i = 1; i < 6; i++)
			count += data[i];
		cout << s << " ";
		printf("%.2lf\n", count / 5);
	}
	return 0;
}

发表于 2017-04-24 19:02:18 回复(0)
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			double max = 0;
			double min = 100;
			double sum = 0;
			for (int i = 0; i < 7; i ++ ) {
				double a = sc.nextDouble();
				sum += a;
				min = min < a ? min : a;
				max = max > a ? max : a;
			}
			String name = sc.next();
			System.out.println(name + " " + new DecimalFormat("#0.00").format((sum - min - max) / 5));
		}
	}
}

发表于 2016-10-13 01:38:45 回复(0)
排序,然后对中间数求平均数
发表于 2015-10-16 16:17:14 回复(0)