AcWing 1634. PAT单位排行
原题链接
简单
作者:
mkuiwu
,
2021-01-01 11:01:57
,
所有人可见
,
阅读 427
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int N = 1e5+10;
struct School
{
string name;
double score;
int cnt;
bool operator < (const School & t) const{
if(score != t.score) return score > t.score;
if(cnt != t.cnt) return cnt < t.cnt;
return name < t.name;
}
};
unordered_map<string, School> school_map;
int main(){
int n;
cin >> n;
string id, school_name;
double score;
for(int i = 0; i < n; i++){
cin >> id >> score >> school_name;
// 先转换大小写
for(auto &c : school_name) c = tolower(c);
if(id[0] == 'B') score /= 1.5;
else if(id[0]=='T') score *= 1.5;
school_map[school_name].name = school_name;
school_map[school_name].score += score;
school_map[school_name].cnt++;
}
vector<School> res;
for(auto it : school_map){
it.second.score = floor(it.second.score +1e-8 ); // 这个精度问题是真的大坑
res.push_back(it.second);
}
sort(res.begin(), res.end());
cout << res.size()<<endl;
int rank = 1;
int last_rank = 1;
int last_score = res[0].score;
cout << rank << ' '<<res[0].name<<' '<<last_score << ' '<< res[0].cnt<<endl;
for(int i = 1; i < res.size(); i++){
rank++;
if(res[i].score != last_score){
last_rank = rank;
last_score = res[i].score;
}
cout << last_rank << ' '<<res[i].name<<' '<<last_score << ' '<< res[i].cnt<<endl;
}
return 0;
}