题目:

分数线划定

题目解析

看注释

代码

#include <bits/stdc++.h>
using namespace std;

class Student { // 定义一个类
	public:
		string k; // 报名号
		int s; // 成绩
};

bool cmp(Student &a, Student &b) { // 自定义排序函数
	if (a.s == b.s) { // 如果成绩相同
		return a.k < b.k; // 返回报名号小的
	} else {
		return a.s > b.s; // 返回成绩高的
	}
}

int main() {
	Student st[5005];
	int n, m, line, ct = 0;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> st[i].k >> st[i].s;
	} // 读入·
	sort(st + 1, st + 1 + n, cmp); // 排序
	line = st[int(m * 1.5)].s; // 按题目要求得到录取线分数
	for (int i = 1; i <= n; ++i) { // 遍历得到被录取的人的个数
		if (st[i].s >= line) {
			ct++;
		}
	}
	cout << line << ' ' << ct << endl; // 输出分数线和录取人数
	for (int i = 1; i <= ct; ++i) { // 输出
		cout << st[i].k << ' ' << st[i].s << endl;
	}
	return 0;
}