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 ...
随机推荐
- NFV及vIMS的部署实施
随着5G和物联网等领域的快速发展,移动数据业务飞速增长,而传统电信网络基于专用硬件的架构和封闭式的网元,已经成为运营商拓展新业务的严重障碍.NFV能够根据用户和业务需求灵活动态地进行网络资源配置,实现 ...
- docker定义数据卷及数据卷的备份恢复
前言:生产环境中使用docker时,往往需要对数据进行持久化(只有把容器导出为镜像,才能够保存写的数据,否则容器删除或者停止,所有数据都会没有),或者需要在多个容器之间进行数据共享,这必然涉及容器的数 ...
- 使用mybatis如果类属性名和数据库中的属性名不一样取值就会为null
使用mybatis时如果类属性名和数据库中的属性名不一样取值就会为null 这是不能再去改变javabean中的属性,只能改变sql语句.语句如下所示: <select id="sel ...
- 值提供器 AND 模型绑定器
本章介绍了值提供器的作用,ASP MVC自带的5中值提供器.以及模型绑定器的作用,自定义模型绑定器并使用自定义的模型绑定器(类型上加上[ModelBinder(typeof(xx))]或者在全局模型绑 ...
- JDBC相关总结
JDBC statement的相关总结 1.Statement.PreparedStatement和CallableStatement都是接口(interface). 2.Statement继承自Wr ...
- 019对象——对象 method_exists property_exists instanceof
<?php /** * 19 对象 method_exists property_exists instanceof */ //method_exists() 判断方法是否存在,第一个参数对象或 ...
- 原创:Javascript DI!Angular依赖注入的实现原理
DI是Angular的特色功能,而在Angular 2.0的计划中,DI将成为一个独立的模块,参见 https://github.com/angular/di.js 这意味着它也有机会被用于nodej ...
- DRF 的视图,路由和渲染器
DRF 的视图,路由和渲染器 1 视图 简单的增删改查 : ModelViewSet; 复杂的操作使用APIView 和 GenericViewSet APIView(View) class Home ...
- Arcgis For Android之离线地图实现的几种方式
为什么要用,我想离线地图的好处是不言而喻的,所以很多人做系统的时候都会考虑用离线地图.在此,我给大家介绍几种Arcgis For Android下加载离线地图的方式. 在Arcgis For Andr ...
- Windows下修改hosts并且让他立即生效
1.打开hosts所在的目录 Win+R->C:\windows\System32\drivers\etc 2.编辑hosts文件 使用Notepad++或者记事本以管理员身份打开hosts,修 ...