其他分享
首页 > 其他分享> > 1085 PAT单位排行 (25 point(s)) (测试点五)

1085 PAT单位排行 (25 point(s)) (测试点五)

作者:互联网

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

struct School{
	string name;
	double score = 0;
	int peo = 0;
};

struct cmp {
  bool operator()(const School a, const School b) {
  	if(a.score != b.score) return a.score > b.score;
  	if(a.peo != b.peo) return a.peo < b.peo;
	return a.name < b.name;
  }
};

int main() {
	int n;
	map<string, School> sch;
	cin >> n;
	while(n--){
		string id, sname;
		int score;
		cin >> id >> score >> sname;
		// 不区分大小写
		transform(begin(sname), end(sname), begin(sname), ::tolower);
		
		// 输入对应学校的数据
		// 判断哪个比赛
		if(id[0] == 'B') {sch[sname].score += score * 1.0 / 1.5;} 
		if(id[0] == 'A') {sch[sname].score += score ;} 
		if(id[0] == 'T') {sch[sname].score += score * 1.5;} 
		sch[sname].peo++;
		sch[sname].name = sname;
	}
	vector<School> ans;
	for(auto s: sch)
		ans.push_back(School{s.first, (int)s.second.score, s.second.peo});
	sort(begin(ans), end(ans), cmp());
	
	// 编号 保存上一个输出的分数 
	int i = 1, j = 1, last = -1;
	cout << ans.size() << endl;
	for(auto a: ans){
		// 如果分数不一样则更新编号 
		if(last != a.score) {
			j = i;
			last = a.score;
		}
		cout << j << " " << a.name << " " << (int)a.score << " " << a.peo << endl;
		i++;
	}
}

标签:25,1085,sname,自定义,测试点,int,second,score,peo
来源: https://www.cnblogs.com/Atl212/p/15306746.html