PAT_A1141#PAT Ranking of Institutions
?Source:
Description:
Input Specification:
Output Specification:
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:
Attention:
Code:1 /* 2 Data: 2019-05-24 09:43:26 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 17 #include<cstdio> 18 #include<iostream> 19 #include<algorithm> 20 #include<map> 21 #include<string> 22 using namespace std; 23 const int M=1e5+10; 24 int pt=1; 25 struct node 26 { 27 string id; 28 double score; 29 int num; 30 }info[M]; 31 map<string,int> mp; 32 33 int ToInt(string s) 34 { 35 if(mp[s]==0) 36 { 37 mp[s]=pt; 38 info[pt].num=0; 39 info[pt].score=0; 40 info[pt].id=s; 41 return pt++; 42 } 43 else 44 return mp[s]; 45 } 46 47 bool cmp(node a,node b) 48 { 49 if((int)a.score != (int)b.score) 50 return a.score > b.score; 51 else if(a.num != b.num) 52 return a.num < b.num; 53 else 54 return a.id < b.id; 55 } 56 57 int main() 58 { 59 #ifdef ONLINE_JUDGE 60 #else 61 freopen("Test.txt","r",stdin); 62 #endif 63 64 int n; 65 scanf("%d",&n); 66 for(int i=0; i<n; i++) 67 { 68 string id,stu; 69 double score; 70 cin >> id >> score >> stu; 71 transform(stu.begin(),stu.end(),stu.begin(),::tolower); 72 int sch = ToInt(stu); 73 if(id[0]==‘T‘) 74 score*=1.5; 75 else if(id[0]==‘B‘) 76 score/=1.5; 77 info[sch].score += score; 78 info[sch].num++; 79 } 80 sort(info+1,info+pt,cmp); 81 printf("%dn",pt-1); 82 int r=1; 83 for(int i=1; i<pt; i++) 84 { 85 if(i==1 || (int)info[i].score!=(int)info[i-1].score) 86 r=i; 87 cout<<r<<‘ ‘<<info[i].id<<‘ ‘<<(int)info[i].score<<‘ ‘<<info[i].num<<endl; 88 } 89 90 return 0; 91 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |