首页 > 其他 > 详细

1141 PAT Ranking of Institutions

时间:2020-03-14 19:22:15      阅读:41      评论:0      收藏:0      [点我收藏+]

 中文版

无需构造函数,快速初始化结构体。

技术分享图片

 

 技术分享图片

 1 #include<iostream>
 2 #include<cctype>
 3 #include<vector>
 4 #include<unordered_map>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 struct School {
 9     string name;
10     int tws,ns;
11 };
12 
13 bool cmp(const School &a,const School &b) {
14     if(a.tws != b.tws) return a.tws > b.tws;
15     if(a.ns != b.ns) return a.ns < b.ns;
16     return a.name < b.name;
17 }
18 int main() {
19     int n;
20     cin>>n;
21     string id,school;
22     double score;
23     unordered_map<string,double> mp;
24     unordered_map<string,int> num;
25     for(int i = 0; i < n; ++i) {
26         cin>>id>>score>>school;
27         for(int j = 0; j < school.size(); ++j) school[j] = tolower(school[j]);
28         if(id[0] == B) score /= 1.5;
29         else if(id[0] == T) score *= 1.5;
30         mp[school] += score;
31         num[school]++;
32     }
33     cout<<mp.size()<<endl;
34     vector<School> v;
35     for(auto it:mp) v.push_back({it.first,(int)it.second,num[it.first]});
36     sort(v.begin(),v.end(),cmp);
37     int r = 1;
38     for(int i = 0; i < v.size(); ++i) {
39         if(i > 0 && v[i].tws != v[i-1].tws)
40             r = i+1;
41         printf("%d %s %d %d\n",r,v[i].name.c_str(),v[i].tws,v[i].ns);
42     }
43     return 0;
44 }

技术分享图片

 

1141 PAT Ranking of Institutions

原文:https://www.cnblogs.com/keep23456/p/12493504.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!