PAT 1085 PAT单位排行 (Microsoft_zzt)
https://pintia.cn/problem-sets/994805260223102976/problems/994805260353126400
每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜。本题就请你实现这个功能。
输入格式:
输入第一行给出一个正整数 N(≤),即考生人数。随后 N 行,每行按下列格式给出一个考生的信息:
准考证号 得分 学校
其中准考证号是由 6 个字符组成的字符串,其首字母表示考试的级别:B代表乙级,A代表甲级,T代表顶级;得分是 [0, 100] 区间内的整数;学校是由不超过 6 个英文字母组成的单位码(大小写无关)。注意:题目保证每个考生的准考证号是不同的。
输出格式:
首先在一行中输出单位个数。随后按以下格式非降序输出单位的排行榜:
排名 学校 加权总分 考生人数
其中排名是该单位的排名(从 1 开始);学校是全部按小写字母输出的单位码;加权总分定义为乙级总分/1.5 + 甲级总分 + 顶级总分*1.5的整数部分;考生人数是该属于单位的考生的总人数。
学校首先按加权总分排行。如有并列,则应对应相同的排名,并按考生人数升序输出。如果仍然并列,则按单位码的字典序输出。
输入样例:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu
输出样例:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
代码:
#include <cstdio>
#include <string>
#include <map>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; map<string, int> s_n;
map<int, string> n_s; const int maxn = 1e5 + 10;
struct X {
string name;
int a[3];
int g;
int num;
}s[maxn]; bool cmp(const X& a, const X& b) {
if (a.g != b.g) return a.g > b.g;
if (a.num != b.num) return a.num < b.num;
return a.name < b.name;
} int main() {
int n;
scanf("%d", &n);
int sz = 0;
for (int i = 1; i <= n; i++) {
string id;
int x;
string name;
cin >> id >> x >> name;
for (int j = 0; j < name.length(); j++) {
if (name[j] >= 'A' && name[j] <= 'Z') {
name[j] = name[j] - 'A' + 'a';
}
} int h = s_n[name];
if (h == 0) {
sz++;
s_n[name] = sz;
n_s[sz] = name;
h = sz;
}
s[h].name = name;
s[h].num++; int o;
if (id[0] == 'A') o = 0;
else if (id[0] == 'B') o = 1;
else if (id[0] == 'T') o = 2;
s[h].a[o] += x;
} for (int i = 1; i <= sz; i ++) {
s[i].g = (int)(1.0 * s[i].a[0] + 1.0 * s[i].a[1] / 1.5 + 1.0 * s[i].a[2] * 1.5);
} sort(s + 1, s + sz + 1, cmp); printf("%d\n", sz);
int rank = 1;
for (int i = 1; i <= sz; i++) {
if (s[i].g != s[i - 1].g) rank = i;
cout << rank << " " << s[i].name << " " << s[i].g << " " << s[i].num << endl;
}
return 0;
}
PAT 1085 PAT单位排行 (Microsoft_zzt)的更多相关文章
- PAT 1085 PAT单位排行(25)(映射、集合训练)
1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤105),即考生人数.随 ...
- PAT 1085 PAT单位排行
每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤10^5),即考生人数.随后 N 行,每行按下列格式给出一个考生的信 ...
- PAT(B) 1085 PAT单位排行(Java:20分)
题目链接:1085 PAT单位排行 (25 point(s)) 题目描述 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式 输入第一行给出一个正整数 N ...
- 1085. PAT单位排行 (25)
每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数N(<=105),即考生人数.随后N行,每行按下列格式给出一个考生的信 ...
- P1085 PAT单位排行
转跳点:
- PAT 1085 Perfect Sequence
PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...
- 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] 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 ...
随机推荐
- Java NIO (1)
Java NIO (1) 看了下java核心技术这本书 关于nio的部分介绍比较少,而且如果自己写服务器的话nio用的还是比较多,整理一下nio的资料 java中nio主要是三个组件 Buffers ...
- Git 创建并管理局域网仓库
Git 作为当前比较流行的代码管理工具,可以实现多人协作,不同版本代码管理. 本文内容基于Ubuntu. 0. 配置git信息 git config --global user.name XXX # ...
- DotNetty学习笔记
DotNetty项目本身的示例很容易运行起来,但是具体到真实的应用场景,还是需要进一步理解DotNetty的通道处理细节,这样才能够在实际项目应用中处理具体的问题. 简单的场景下会有以下几个问题,第一 ...
- Firefox+Burpsuite抓包配置(可抓取https)
0x00 以前一直用的是火狐的autoproxy代理插件配合burpsuite抓包 但是最近经常碰到开了代理却抓不到包的情况 就换了Chrome的SwitchyOmega插件抓包 但是火狐不能抓包的问 ...
- C#基础之Equals和Dispose
1.equal()和运算符==的区别 由于C#中有值类型和引用类型,那么相等也分为值相等和引用相等.先来看一个值类型简单的例子,顺便也写了string类型的比较. static void Main(s ...
- 【LG4631】[APIO2018]Circle selection 选圆圈
[LG4631][APIO2018]Circle selection 选圆圈 题面 洛谷 题解 用\(kdt\)乱搞剪枝. 维护每个圆在\(x.y\)轴的坐标范围 相当于维护一个矩形的坐标范围为\([ ...
- 让div跟着鼠标移动
朋友求助帖 具体实现代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- 验证码示例代码演示——以php为例
运行 · 修改index.php(图片验证码的生成示例) [html] view plain copy initNECaptcha({ captchaId: 'YOUR_CAPTCHA_ID', // ...
- LumiSoft.Net 收发邮件
一:LumiSoft.Net简介 Lumisoft is a software development company specialised in mobile phones and tablets ...
- shell loop
#!/bin/sh date i=0 while [ $i -le 30 ] do echi $i /usr/sbin/r2/np_test_acl -f rule.txt i=$(e ...