AcWing 1634. PAT单位排行
原题链接
简单
作者:
leo123456
,
2020-09-04 17:11:35
,
所有人可见
,
阅读 890
#include<iostream>
#include<vector>
#include<unordered_map>
#include<string>
#include<algorithm>
using namespace std;
struct school
{
string name;
double score;
int num;
};
bool cmp(school a,school b)
{
if(a.score!=b.score) return a.score>b.score;
else if(a.num!=b.num) return a.num<b.num;
else return a.name<b.name;
}
int main()
{
int n;
cin>>n;
unordered_map<string,school> sch;
for(int i=0;i<n;i++)
{
string id,sname;
double score;
cin>>id>>score>>sname;
if(id[0]=='B') score/=1.5;
else if(id[0]=='T') score*=1.5;
for(auto& c:sname) c=tolower(c);
sch[sname].name=sname;
sch[sname].score+=score;
sch[sname].num++;
}
vector<school> v;
for(auto it:sch)
{
it.second.score = (int)(it.second.score+1e-8);//double精度 23.9999999999
v.push_back(it.second);
}
sort(v.begin(),v.end(),cmp);
cout<<v.size()<<endl;
int rank=1;
for(int i=0;i<v.size();i++)
{
auto t=v[i];
if(i&&t.score!=v[i-1].score) rank=i+1;
printf("%d %s %d %d\n",rank,t.name.c_str(),(int)t.score,t.num);
}
return 0;
}