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 ...
随机推荐
- java-登陆界面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 简易的解决方式linker command failed with exit code 1 (use -v to see invocation)
linker command failed with exit code 1 (use -v to see invocation) 遇到这个问题先不要慌,不用纠结是不是自己改动了什么代码导致的. 长话 ...
- 10074 启用开发者模式 for vs2015rc
1. 关于VS2015RC 有两个版本,它们都包含了Windows 10 SDK. 社区版:免费,可以开发Windows UAP应用.iOS和Android应用.在 帮助->注册产品 菜单可以登 ...
- hdu 5974 A Simple Math Problem
A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- CSS:Tutorial two
1.CSS Text text color, text align... Text Decoration The text-decoration property is used to set or ...
- 【python】没有root权限的时候安装Python package
下载相关位置的包 1.首先在git上下载对应的包: 搜索package github,找到地址.使用 git clone https://xxx.git 命令 2.使用python setup.py ...
- Arcgis Android API开发之离线地图
最近一直在倒腾Arcgis Android API等相关的东西,想把自己的做的图放到地图上去,也就是离线地图,穷人一般是没有钱的,一个月好几十的流量是开不起的,所以就左捉摸,右思考,看着API里面有离 ...
- "==" 与 "is"的区别
Is there a difference between `==` and `is` in Python? "=="是比较内容相当;"is"是比较对象的id是 ...
- OneNote如何使用
自从安装了Office2013后发现office套件中有很多的好东西,今天要和大家分享的就是Office套件中的OneNote软件,这狂软件能够很方便的记录我们生活中的一些学习资料.一些决绝方法的经验 ...
- C# chart控件运用
为了弄一个实时数据显示的窗口,最近一周时间都耗在这个控件上了,属性有点多(下面列的是一些常用的) 后来干脆写代码把他们封装起来,各个chart直接来调用它,省得到属性里面去设置. chart内的一些元 ...