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 ...
随机推荐
- css 中的background:transparent到底是什么意思有什么作用
有时我在看css时,看到有的css属性定义为background:transparent.意思就是背景透明.实际上background默认的颜色就是透明的属性.所以写和不写都是一样的 有段时间没写文章 ...
- 用纯css写一个常见的小三角形
.test{ margin:50px auto; width: 0; height: 0; overflow: hidden; border-width: 10px; border-color: #0 ...
- 【Android压力测试】monkey压力测试
1.首先安装adb.java环境 2.下载地址: 链接: https://pan.baidu.com/s/1i5xltpN 密码: ra6g monkey 很简单的理解是 像猴子一样一顿点乱点,看是否 ...
- 控制语句1:真假与if 语句
一.真假与运算符 1.1 真假的划分.查看 任何数据都可以分为两类:True 与 False False : 0,None,空的数据结构例如:[] ,{},str1 = '' True :除了上面情 ...
- TI IPNC Web网页之GoDB开发环境
介绍 下面介绍DM8127/DM385 IPNC RDK中网页制作相关的东东. 具体来说,各位获得这个RDK包时有以下文件: IPNC_RDK_DM812x_DM385_Version3.5.0.ta ...
- 2017.10.31 Enginer+position+statement
一.The basic information Post name Engineering manager Department Engineering Post member A24645 imme ...
- Django常用插件
1 富文本编辑器--tinymce 2 分页器--pure pagination 视图中 all_orgs_list = CourseOrg.objects.all() try: page = req ...
- Python 调用C函数
/******************************************************************** * Python 调用C函数 * 说明: * Tony在处理 ...
- 启动mysql 失败,“Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' ”
一.Mac OS X的升级或其他原因可能会导致MySQL启动或开机自动运行时 在MySQL操作面板上会提示“Warning:The /usr/local/mysql/data directory is ...
- 编写实现字符串拷贝函数strcpy()完整版
有个题目编程实现字符串拷贝函数strcpy(),很多人往往很快就写出下面这个代码. void strcpy( char *strDest,char *strSrc ) { while(( *strDe ...