AcWing 1634. PAT单位排行
原题链接
简单
作者:
狮子星
,
2025-03-26 11:46:43
·江西
,
所有人可见
,
阅读 1
利用pair和vector进行三关键字排序
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
unordered_map<string , vector<pair<string , int>>> Hash;
vector<pair<int , pair<int , string>>> res;
int main()
{
int n;
cin >> n;
while(n-- ) {
string id , name;
int sc;
cin >> id >> sc >> name;
for(auto& x : name) x = tolower(x);
Hash[name].push_back({id , sc});
}
cout << Hash.size() << endl;
for(auto& [x , y] : Hash) {
double sum = 0.0;
for(auto& [z , w] : y)
sum += z[0] == 'T' ? w * 1.5 : (z[0] == 'B' ? w * 1.0 / 1.5 : w);
res.push_back({-(int)(sum + 1e-8) , {y.size() , x}});
}
sort(res.begin() , res.end());
for(int i = 0 , rank = 1 ; i < res.size() ; i++ ) {
if(i && res[i].first != res[i - 1].first) rank = i + 1;
printf("%d %s %d %d\n" , rank , res[i].second.second.c_str() , -res[i].first , res[i].second.first);
}
return 0;
}