L2-027. 名人堂与代金券

L2-027. 名人堂与代金券

时间限制
150 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈越

对于在中国大学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
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct student {
	string name;
	int grade;
	student(string name, int grade) {
		this->name = name;
		this->grade = grade;
	}
};
int max(int a, int b) {
	return a > b ? a : b;
}
bool cmp(student& a, student& b) {
	if (a.grade != b.grade)
		return a.grade > b.grade;
	else
		return a.name < b.name;
}


int main()
{
	//freopen("1.txt", "r", stdin);
	int N, G, K;
	int count = 0;
	cin >> N >> G >> K;
	vector< student > list;
	for (int i = 0; i < N; i++) {
		string name;
		int grade;
		cin >> name >> grade;
		if (60 <= grade && grade < G)
			count += 20;
		else if (grade >= G)
			count += 50;
		list.push_back(student(name, grade));
	}
	sort(list.begin(), list.end(), cmp);
	cout << count << endl;
	int flag = 0;
	for (int i = 0;; i++) {
		if (list[flag].grade != list[i].grade)
			flag = i;
		if (K < flag + 1)
			break;
		printf("%d %s %d\n", flag + 1, list[i].name.c_str(), list[i].grade);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/wbb1997/article/details/79965853