团体程序设计天梯赛 L2-027 名人堂与代金券 (25分)

题目链接:

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

思路:

排序即可,注意计算排名时并列的情况

代码:

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e4 + 5;
int n, g, k;
struct P { 
	int x; string s;
	bool operator < (const P & a) const {
		return x == a.x ? s < a.s : x > a.x;	
	}
}rk[maxn];

int main() {
#ifdef MyTest
	freopen("Sakura.txt", "r", stdin);
#endif	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> g >> k;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		cin >> rk[i].s >> rk[i].x;
		if(rk[i].x >= g) ans += 50;
		else if(rk[i].x >= 60) ans += 20;
	}
	cout << ans << '
';
	sort(rk + 1, rk + n + 1);
	int cnt;
	for(int i = 1; i <= n; i++) {
		if(i == 1 || rk[i].x < rk[i - 1].x) cnt = i;
		if(cnt > k) break;
		cout << cnt << ' ' << rk[i].s << ' ' << rk[i].x << '
';
	}
	return 0;
}
原文地址:https://www.cnblogs.com/yuhan-blog/p/12308655.html