1141 PAT Ranking of Institutions
题意:给出考生id(分为乙级、甲级和顶级),取得的分数和所属学校。计算各个学校的所有考生的带权总成绩,以及各个学校的考生人数。最后对学校进行排名。
思路:本题的研究对象是学校,而不是考生!因此,建立学校的结构体Record,记录学校的校名,考生人数,排名,成绩等信息。利用map<校名,该学校对应的结构体>构造映射,然后在读入数据的时候就可以更新该学校的分数,学生人数。数据读入完毕后,根据计算规则求出各个学校的带权总成绩,再把结构体放到vector中排序一下,确定排名,就好了。
代码:
#include <cstdio> #include <cctype> #include <string> #include <vector> #include <map> #include <iostream> #include <algorithm> #include <fstream> using namespace std; struct Record{ int rank; string sch; int ScoreB,ScoreA,ScoreT,tws; int cnt; Record():rank(),sch(),ScoreA(),ScoreT(),tws(),cnt(){} }; map<string,Record> mp; vector<Record> vec; bool cmp(Record a,Record b) { if(a.tws!=b.tws) return a.tws>b.tws; else if(a.cnt!=b.cnt) return a.cnt<b.cnt; else return a.sch<b.sch; } int main() { //ifstream cin("pat.txt"); int n; cin>>n; string sch,id; int score; ;i<n;i++){ cin>>id>>score>>sch; ;i<sch.size();i++) sch[i]=tolower(sch[i]); mp[sch].cnt++; mp[sch].sch=sch; ]=='B') mp[sch].ScoreB+=score; ]=='A') mp[sch].ScoreA+=score; else mp[sch].ScoreT+=score; } for(auto it:mp){ Record rec=it.second; rec.tws=rec.ScoreB/1.5 + rec.ScoreA + rec.ScoreT*1.5; vec.push_back(rec); } sort(vec.begin(),vec.end(),cmp); ;i<vec.size();i++){ ) vec[i].rank=; ].tws) vec[i].rank=vec[i-].rank; ; } cout<<vec.size()<<'\n'; for(auto it:vec) cout<<it.rank<<' '<<it.sch<<' '<<it.tws<<' '<<it.cnt<<'\n'; ; }
1141 PAT Ranking of Institutions的更多相关文章
- 1141 PAT Ranking of Institutions[难]
1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...
- PAT 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- [PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- 1141 PAT Ranking of Institutions (25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT 1141 PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT_A1141#PAT Ranking of Institutions
Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...
- A1141. PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT Ranking (排名)
PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...
随机推荐
- coredata 数据库升级
在真实开发中,因为需求是不断变化的,说不定什么时候就需要往模型里添加新的字段,添加新的模型,甚至是大规模的重构:所以数据的迁移就显得尤为重要了. CoreData 中,数据迁移本质就是把旧的 SQLi ...
- flash滚动图片遮住二级下拉菜单解决方法
如上图所示,在进行排版时,如果不注意会遇到二级下拉菜单被下边的img图片遮住.此种情况在ie7 8 中出现. 解决方法:给二级下拉菜单添加z-index:9999;position:relative; ...
- 四十一 Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)基本的索引和文档CRUD操作、增、删、改、查
elasticsearch(搜索引擎)基本的索引和文档CRUD操作 也就是基本的索引和文档.增.删.改.查.操作 注意:以下操作都是在kibana里操作的 elasticsearch(搜索引擎)都是基 ...
- <mvc:default-servlet-handler/>的作用
优雅REST风格的资源URL不希望带 .html 或 .do 等后缀.由于早期的Spring MVC不能很好地处理静态资源,所以在web.xml中配置DispatcherServlet的请求映射,往往 ...
- 命令行连接db2数据库
在cmd界面执行db2cmd命令 然后在db2cmd界面执行db2命令 然后执行 CONNECT TO UIBS USER DB2INST1 USING 123456命令
- Qt WebKit 学习的说明
(转自:http://it.100xuexi.com/view/otdetail/20120827/4021c662-b917-44d9-8284-910cac713c23.html) QT Webk ...
- OLED取模笔记
- 在VMware永久修改网
如果想要永久性设置固定的IP地址,需要通过编辑网卡配置文件实现: 现在使用VI编辑器打开配置文件. # vi /etc/sysconfig/network-scripts/ifcfg-eth0 虽然直 ...
- EasyPlayer实现Android MediaMuxer录像MP4(支持G711/AAC/G726音频)
本文转自EasyDarwin开源团队John的博客:http://blog.csdn.net/jyt0551/article/details/72787095 Android平台的MediaMuxer ...
- Android数据库代码优化(1) - 从Google的数据库guide说起
假如我们没有任何在Android上使用SQLite的经验,现在要开始在工作中用SQLite存储一些数据.OK, 我们去看google的官方培训文档吧,http://developer.android. ...