PAT_A1141#PAT Ranking of Institutions
Source:
Description:
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 (≤), 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 andT
the top level;Score
is an integer in [0, 100]; andSchool
is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed thatID
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 ofScoreB/1.5 + ScoreA + ScoreT*1.5
, whereScoreX
is the total score of the testees belong to this institution on levelX
; andNs
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 ofNs
. 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 hypu
Sample Output:
5 1 cmu 192 2 1 au 192 3 3 pku 100 1 4 hypu 81 2 4 lanx 81 2
Keys:
- map(C++ STL)
- string(C++ STL)
- 快乐模拟
Attention:
- 字符串转换为小写:transform(s.begin(),s.end(),s.begin(),::tolower);
- 字符串转换为大写:transform(s.begin(),s.end(),s.begin(),::toupper);
- 分数用double存储,比较总分时再取整数部分,若计算各个Int再相加,会有误差
- cmp,rank,printf,三处的比分都要用整数,各对应一个测试点
Code:
1 /* 2 Data: 2019-08-06 20:19:45 3 Problem: PAT_A1141#PAT Ranking of Institutions 4 AC: 33:40 5 6 题目大意: 7 按分数排名 8 输入: 9 第一行给出,考试人数N<=1e5 10 接下来N行给出,ID(1位字母+5位数字),分数[0,100],学校(<=6,大小写敏感) 11 输出: 12 第一行输出,学校总数M 13 接下来M行,排名(>=1), 学校(小写),总分(B/1.5+A+T*1.5),考生数 14 排序规则,总分递减,人数递增,学校字典序 15 */ 16 #include<cstdio> 17 #include<string> 18 #include<map> 19 #include<vector> 20 #include<iostream> 21 #include<algorithm> 22 using namespace std; 23 const int M=1e5+10; 24 int pos=1; 25 map<string,int> mp; 26 struct node 27 { 28 string sch; 29 double score; 30 int num; 31 }ans[M]; 32 33 int Hash(string s) 34 { 35 if(mp[s]==0) 36 { 37 ans[pos]=node{s,0,0}; 38 mp[s]=pos++; 39 } 40 return mp[s]; 41 } 42 43 bool cmp(const node &a, const node &b) 44 { 45 if((int)a.score != (int)b.score) 46 return a.score > b.score; 47 else if(a.num != b.num) 48 return a.num < b.num; 49 else 50 return a.sch < b.sch; 51 } 52 53 int main() 54 { 55 #ifdef ONLINE_JUDGE 56 #else 57 freopen("Test.txt", "r", stdin); 58 #endif // ONLINE_JUDGE 59 60 int n; 61 scanf("%d", &n); 62 for(int i=0; i<n; i++) 63 { 64 string id,sc; 65 double grade; 66 cin >> id >> grade >> sc; 67 transform(sc.begin(),sc.end(),sc.begin(),::tolower); 68 int pt = Hash(sc); 69 if(id[0]=='T') grade *= 1.5; 70 if(id[0]=='B') grade /= 1.5; 71 ans[pt].score += grade; 72 ans[pt].num++; 73 } 74 sort(ans+1,ans+pos,cmp); 75 int r=1; 76 printf("%d\n", pos-1); 77 for(int i=1; i<pos; i++) 78 { 79 if(i!=1 && (int)ans[i-1].score != (int)ans[i].score) 80 r=i; 81 printf("%d %s %d %d\n", r,ans[i].sch.c_str(),(int)ans[i].score,ans[i].num); 82 } 83 84 return 0; 85 }