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 ...
随机推荐
- JSP导入包
1. <%@page import="java.util.Date, mianBao.*, z_utils.*"%> 2. 3.
- Python 导出数据from Mysql
环境 Anaconda3 Python 3.6, Window 64bit 目的 从MySQL数据库读取目标表数据,并处理 代码 # -*- coding: utf-8 -*- import pand ...
- mysql中的左连接右连接内连接
一. 初始化SQL语句 /*join 建表语句*/ drop database if exists test; create database test; use test; /* 左表t1*/ dr ...
- Educational Codeforces Round 23D
给n个数求每个子区间的价值,区间的价值是最大值-最小值 套路题= =,分别算最大值和最小值的贡献,用并查集维护,把相邻点连一条边,然后sort,求最大是按边价值(两个点的最大价值)小的排,求最小是按最 ...
- MailUtils 测试邮件是否发送
import java.util.Properties; import javax.mail.Message; import javax.mail.Session; import javax.mail ...
- ndk+opencv安装+各种错误分析(新版安装,编译不需要Cygwin 和Sequoyah了)
鼓捣了两三天,终于成功算跑通了一个简单的程序.下面说说具体的安装: 因为从同学那里拷过来的eclipse 就有adt cdt 的插件.所以这两个就不用再安装了.(需要的话自己安装) 具体说下安装过程: ...
- 【51nod-1596】搬货物
现在有n个货物,第i个货物的重量是 2wi .每次搬的时候要求货物重量的总和是一个2的幂.问最少要搬几次能把所有的货物搬完. 样例解释: 1,1,2作为一组. 3,3作为一组. Input 单组测试数 ...
- NGUI 学习使用
http://www.tasharen.com/forum/index.php?board=12.0
- BasicExcel的使用
from:http://www.cnblogs.com/paullam/p/3705924.html 使用的平台:vs2013 控制台 创建时需要注意, 安全开发生命周期(SDL)检查 不能勾选( ...
- c printf打印格式
关于小数点位数的举例: <pre lang="c" escaped="true">#include <stdio.h> /* 当fah ...