题意:给出学校的名字和每次考试的分数,对应考试的成绩总和和次数
思路:将分数和次数都放在map里,然后排序
注意点:一开始先用double存,最后转成结构体的时候用int存
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
map<string,double>mp;
map<string,int>ns;
struct xx{
string id;
int score;
int cnt;
}school[100005];
bool cmp(xx a,xx b){
if(a.score==b.score){
if(a.cnt==b.cnt)
return a.id<b.id;
return a.cnt<b.cnt;
}
return a.score>b.score;
}
int main(){
int n;
cin>>n;
mp.clear();
int sum=0;
while(n--){
string sid,sname;
int score;
cin>>sid>>score>>sname;
for(int i=0;i<sname.size();i++){
if(sname[i]>='A'&&sname[i]<='Z')
sname[i]=sname[i]-'A'+'a';
}
if(mp[sname]==0&&ns[sname]==0)
sum++;
if(sid[0]=='A'){
mp[sname]+=score;
}else if(sid[0]=='B'){
mp[sname]+=score*1.0/1.5;
}else
mp[sname]+=score*1.0*1.5;
ns[sname]++;
}
cout<<sum<<endl;
map<string,double>::iterator it;
int index=0;
for(it=mp.begin();it!=mp.end();it++,index++){
school[index].cnt=ns[it->first];
school[index].id=it->first;
school[index].score=it->second;
}
sort(school,school+sum,cmp);
int rank=0;
int num=0;
int fscore=-1;
for(int i=0;i<sum;i++){
num++;
if(school[i].score!=fscore){
rank=num;
fscore=school[i].score;
}
cout<<rank<<" "<<school[i].id<<" "<<school[i].score<<" "<<school[i].cnt<<endl;
}
return 0;
}