团体天梯 L2-027 名人堂与代金券 (25 分)

版权声明:有疑问请在评论区回复,邮箱:[email protected] https://blog.csdn.net/qq_40946921/article/details/86612541

L2-027 名人堂与代金券 (25 分)

对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,总评成绩必须达到 60 分及以上,并且有另加福利:总评分在 [G, 100] 区间内者,可以得到 50 元 PAT 代金券;在 [60, G) 区间内者,可以得到 20 元PAT代金券。全国考点通用,一年有效。同时任课老师还会把总评成绩前 K 名的学生列入课程“名人堂”。本题就请你编写程序,帮助老师列出名人堂的学生,并统计一共发出了面值多少元的 PAT 代金券。

输入格式:

输入在第一行给出 3 个整数,分别是 N(不超过 10 000 的正整数,为学生总数)、G(在 (60,100) 区间内的整数,为题面中描述的代金券等级分界线)、K(不超过 100 且不超过 N 的正整数,为进入名人堂的最低名次)。接下来 N 行,每行给出一位学生的账号(长度不超过15位、不带空格的字符串)和总评成绩(区间 [0, 100] 内的整数),其间以空格分隔。题目保证没有重复的账号。

输出格式:

首先在一行中输出发出的 PAT 代金券的总面值。然后按总评成绩非升序输出进入名人堂的学生的名次、账号和成绩,其间以 1 个空格分隔。需要注意的是:成绩相同的学生享有并列的排名,排名并列时,按账号的字母序升序输出。

输入样例:

10 80 5
[email protected] 78
[email protected] 87
[email protected] 65
[email protected] 96
[email protected] 39
[email protected] 87
[email protected] 80
[email protected] 88
[email protected] 80
[email protected] 70

输出样例:

360
1 [email protected] 96
2 [email protected] 88
3 [email protected] 87
3 [email protected] 87
5 [email protected] 80
5 [email protected] 80

 注意:

      最后按排名来确定名人堂,而不是人数,样例中前5名就有6个人

      就算不及格,只要排名靠前,仍然可以进入名人堂(测试的2、3)

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
struct Student {
	string email;
	int grade;
	bool operator<(const Student& o)const {
		return grade != o.grade ? grade > o.grade:email < o.email;
	}
};
int main() {
	int N, G, K, pay = 0;
	string email, tmp;
	cin >> N >> G >> K;
	vector<Student> student(N);
	for (int i = 0; i < N; i++) {
		cin >> student[i].email >> student[i].grade;
		if (60 <= student[i].grade&&student[i].grade < G)
			pay += 20;
		else if (student[i].grade >= G)
			pay += 50;
	}
	sort(student.begin(), student.end());
	int ranking = 0 /*排名*/, count = 0   /*计数器*/;
	int pre = -1;				//前驱分数
	cout << pay << endl;
	for (int i = 0; i<N;i++) {
		count++;
		if (student[i].grade!= pre)	//与前驱分数不同时,更新ranking
			ranking = count;
		if (ranking > K)
			break;
		pre = student[i].grade;
		cout << ranking << " " << student[i].email<< " " << student[i].grade <<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40946921/article/details/86612541