1141. PAT Ranking of Institutions (25)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<=105), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where "ID" is a string of 6 characters with the first one representing the test level: "B" stands for the basic level, "A" the advanced level and "T" the top level; "Score" is an integer in [0, 100]; and "School" is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that "ID" is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where "Rank" is the rank (start from 1) of the institution; "School" is the institution code (all in lower case); "TWS" is the total weighted score which is defined to be the integer part of "ScoreB/1.5 + ScoreA + ScoreT*1.5", where "ScoreX" is the total score of the testees belong to this institution on level X; and "Ns" is the total number of testees who belong to this institution.
The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.
Sample Input:10 A57908 85 Au B57908 54 LanX A37487 60 au T28374 67 CMU T32486 24 hypu A66734 92 cmu B76378 71 AU A47780 45 lanx A72809 100 pku A03274 45 hypuSample Output:
5 1 cmu 192 2 1 au 192 3 3 pku 100 1 4 hypu 81 2 4 lanx 81 2
#include<bits/stdc++.h>
const int maxn =101110;
using namespace std;
struct Node1{ ///结构体1 存输入内容
string id;
int score;
int type;
string school;
};
struct Node2{ ///结构体2 存结果
int rank1;
string school;
int score;
double sct;
int num;
};
int n,len,maxteam;
char c;
Node1 in[maxn];
Node2 ans[maxn],temp;
map<string,Node2>mp; ///用于合并同一学校数据
string s;
///结构体排序函数
int cmp(const Node2 &a, const Node2 &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.school<b.school;
}
}
int main(){
///输入处理
scanf("%d",&n);
for(int i=0;i<n;i++){
cin>>in[i].id; scanf("%d",&in[i].score);cin>>s;
len=s.length();
for(int j=0;j<len;j++){
c=tolower(s[j]);
in[i].school+=c;
}
if(in[i].id[0]=='B')in[i].type=1;
else if(in[i].id[0]=='A')in[i].type=2;
else if(in[i].id[0]=='T')in[i].type=3;
}
Node1 t;
for(int i=0;i<n;i++){
t=in[i];
temp=mp[t.school];
temp.num++;
temp.school=t.school;
if(t.type==1)temp.sct+=(double)t.score/1.5;
else if(t.type==2)temp.sct+=(double)t.score;
else if(t.type==3)temp.sct+=(double)t.score*1.5;
mp[t.school]=temp;
}
map<string,Node2>::iterator it=mp.begin();
int i=0;
for(;it!=mp.end();it++){
it->second.score=it->second.sct;
ans[i++]=it->second;
}
///排序
sort(ans,ans+mp.size(),cmp);
int rak=1,scr=ans[0].score;
maxteam=i;
ans[0].rank1=1;
for(int i=1;i<maxteam;i++){
if(scr==ans[i].score)ans[i].rank1=rak;
else{
rak=i+1;
ans[i].rank1=rak;
scr=ans[i].score;
}
}
cout<<maxteam<<endl;
for(int i=0;i<maxteam;i++){
printf("%d ",ans[i].rank1);
cout<<ans[i].school;
printf(" %d %d\n",ans[i].score,ans[i].num);
}
}