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多线程 - 控制线程
join线程 在某个线程的执行流中调用其他线程的join()方法时,调用线程将被阻塞,直到被join()方法加入的线程完成为止. join()方法有三种重载形式: join():等待被join的线程执 ...
- 使用maven创建项目时报错The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
Description Resource Path Location Type The superclass "javax.servlet.http.HttpServlet" wa ...
- css文本(教程)
1.text-transform --文本转换 定义文本的大小写状态,此属性对中文无意义 取值:capitalize | uppercase | lowercase | none | inherit ...
- 云服务器用ssh登录
本地生成密钥 这里选择在购买前先在本地生成密钥key(分为private key和public key),所以先生成密钥再进行购买,购买完以后直接ssh登录,不需要输入密码(安全性考虑) 其中,pub ...
- OpenCV人脸检测并把图片写成avi视频
读出某一个文件夹下“jpg”后缀的全部图片后,用的OpenCV自带的人脸检测检测图片中的人脸,调整图片的大小写成一个avi视频. 主要是要记录一下CvVideoWriter的用法和如何从文件夹中读取某 ...
- Ceph:pg peering过程分析
转自:https://www.ustack.com/blog/ceph%ef%bc%8dpg-peering/ Peering:互为副本的三个(此处为设置的副本个数,通常设置为3)pg的元数据达到一致 ...
- oracle 常用的系统表查询
(转自:http://blog.csdn.net/marshalchen/article/details/6552103) select * from user_tab_cols where colu ...
- 文字始终均匀分布整个div
html部分 <div id="div"> <span>这是一段话,这是又一段话!</span> </div> js部分 getFu ...
- 使用jmeter做web接口测试
接口测试概述 定义 API testing is a type of software testing that involves testing application programming in ...
- 2 秒杀系统模拟基础实现,使用Redis实现
这一篇,我们来使用redis进行数据存储. 新建一个redis的service实现类 package com.tianyalei.service; import com.tianyalei.model ...