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 ...
随机推荐
- DPDK在OpenStack中的实现
随着云计算与大数据的快速发展,其对数据中心网络的性能和管理提出了更高的要求,但传统云计算架构存在多个I/O瓶颈,由于云平台基本上是采用传统的X86服务器加上虚拟化方式组建,随着40G.100G高速网卡 ...
- 【Android压力测试】monkey压力测试
1.首先安装adb.java环境 2.下载地址: 链接: https://pan.baidu.com/s/1i5xltpN 密码: ra6g monkey 很简单的理解是 像猴子一样一顿点乱点,看是否 ...
- CC攻击工具list
从论文里抠出来的工具列表如下,后面有黑产的工具以及网络上摘录的工具: 分类:(1)有僵尸网络(是否代理服务器)&没有的==>(2)单一url&混合url(多线程,压测为主,dem ...
- 来自lombok的注解(解决idea中的找不到get,set方法,找不到log的问题)
今天看代码,发现idea报错,仔细一看调用的get,set方法bean中都没有,但是运行起来却没有问题,这个让我很疑惑.后来发现在类上有一个以前没见过的注解@Data,大概就是因为有他的原因.这个注解 ...
- 关于HashMap,HashTable,HashSet浅析
首先,最重要的,HashMap 作为一个我们使用非常多的集合.最常被大家认知的是,它是一个key-value形式存储数据的数据结构,可以实现快速的存,取操作. 关于HashMap的源码,我们截取一 ...
- How to Have a Healthy Relationship --shanbei 为单身节写
我在扇贝发现一片好文. Sometimes relationships can seem like a lot of work until you sit back and realize just ...
- php中生成树形菜单
废话不多说!上代码 class tree { /** * 生成树型结构所需要的2维数组 * @var array */ var $arr = array(); /** * 生成树型结构所需修饰符号,可 ...
- Kotlin 第二弹:Android 中 PDF 创建与渲染实践
这是 Kotlin 练习的的第二篇.这一篇的由来是因为刚刚在 Android 开发者官网查看 API 的时候,偶然看到了角落里面的 pdf 相关. 我仔细看看了详细文档,发现这个还蛮有意思的,关键是编 ...
- Java一般要学多久?
其实学java一般要多久?因人而异,有些人资质好,头脑聪明几个月就能学会,有些人天生愚钝,理解能力差,不过勤能补拙,只是时间相对长点 要坚持住.不过java相对于C,C++java而言,java无疑简 ...
- Linux 安全rm
先将shell脚本放在某个全局路径下,如/usr/local/bin #!/bin/sh # safe rm # Don't remove the file, just move them to a ...