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 ...
随机推荐
- JQuery中选择元素的方法:
document.getElementById('div1');document.getElementsByTagName('div');getByClass(document,'box'); $(' ...
- mysql数据库优化课程---9、php用什么写的
mysql数据库优化课程---9.php用什么写的 一.总结 一句话总结:php是用c语言写的,所以php里面的那些模块什么都是c语言 c 1.php用什么写的? c php是用c语言写的,所以php ...
- tomcat学习篇
要求: 为Apache HTTP Server服务器添加JSP网页支持. 能够访问Tomcat容器的Web管理界面,以便管理各种JSP.Servelet应用. u 知识提示 在各种企业级网站应用系统中 ...
- 【scala】应用程序和App特性
一.应用程序 要运行一个Scala对象,必须提供一个独立对象的名称.这个独立对象需要包含一个main方法,该方法接受一个Array[String]作为参数,结果类型为Unit. import Chec ...
- 使用Jenkins自动编译我的 java 项目 git maven jenkins
之前的项目已经将jenkins部署好,现在添加maven项目 准备工作 安装插件 Git plugin Publish Over SSH 全局设置 key: 是 linux服务器的私钥 Global ...
- AFNetworking网络请求与图片上传工具(POST)
AFNetworking网络请求与图片上传工具(POST) .h文件 #import <Foundation/Foundation.h> /** 成功Block */ typedef vo ...
- New Concept English three (39)
26w/m 70errors The rough across the plain soon became so bad that we tried to get Bruce to drive bac ...
- DataV纪录
DataV 是阿里云出品的拖拽式可视化工具,专精于业务数据与地理信息融合的大数据可视化.
- 在ubuntu14.4里编译UBOOT出错
出错信息如下: OBJCOPY examples/standalone/hello_world.bin LDS u-boot.lds LD u-boot./scripts/dtc ...
- Java8新特性Optional、接口中的默认方法与静态方法
Optional Optional 类(java.util.Optional) 是一个容器类,代表一个值存在或不存在,原来用 null 表示一个值不存在,现在 Optional 可以更好的表达这个概念 ...