[PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤10
5
), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where ID is a string of 6 characters with the first one representing the test level: B stands for the basic level, A the advanced level and T the top level; Score is an integer in [0, 100]; and School is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that ID is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where Rank is the rank (start from 1) of the institution; School is the institution code (all in lower case); ; TWS is the total weighted score which is defined to be the integer part of ScoreB/1.5 + ScoreA + ScoreT*1.5, where ScoreX is the total score of the testees belong to this institution on level X; and Ns is the total number of testees who belong to this institution.
The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.
Sample Input:
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
Sample Output:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
题意:第一行输出参加考试的学校数。再按分数、人数、学校名的字典序进行排序。
思路:首先需要构造一个学校结构体,读取输入之后进行分数的计算。然后对结构体实现一个排序。注意需要求得每个学校的总分后在进行取整,不然有一个3分的测试用例过不去。
题解:
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
struct institution {
int rank;
string name;
float score;
int num;
};
string lowCase(string str) {
; i < str.length(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = str[i] - 'A' + 'a';
}
}
return str;
}
bool cmp(institution a, institution b) {
if (a.score != b.score) return a.score > b.score;
else if (a.num != b.num) return a.num < b.num;
else return a.name < b.name;
}
//这里不能直接返回score的取整部分,
//题目的意思是要算出totalscore之后,
//再进行取整,否则有一个3分的用例过不去。
float trueScore(string id, float score) {
];
if (c == 'A') return score;
else if (c == 'B') return score / 1.5f;
else return score * 1.5f;
}
int main() {
int n;
map<string, institution> mapp;
scanf("%d", &n);
string id, school;
float score;
; i < n; i++) {
cin >> id;
cin >> score;
cin >> school;
school = lowCase(school);
score = trueScore(id, score);
if (mapp.find(school) != mapp.end()) {
mapp[school].num++;
mapp[school].score += score;
}
else {
institution ins;
ins.name = school;
ins.num = ;
ins.score = score;
mapp[school] = ins;
}
}
vector<institution> result;
for (map<string, institution>::iterator it = mapp.begin(); it != mapp.end(); it++) {
//对分数进行取整
it->second.score = (int)it->second.score;
result.push_back(it->second);
}
sort(result.begin(), result.end(), cmp);
printf("%d\n", result.size());
;
score = result[].score;
; i < result.size(); i++) {
if (result[i].score != score) {
rank = i + ;
score = result[i].score;
}
cout << rank << " " << result[i].name << " " << (int)result[i].score << " " << result[i].num << endl;
}
;
}
[PAT] 1141 PAT Ranking of Institutions(25 分)的更多相关文章
- PAT乙级:1090危险品装箱(25分)
PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清 ...
- PAT乙级:1070 结绳 (25分)
PAT乙级:1070 结绳 (25分) 题干 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟 ...
- PAT 1141 PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT 乙级 1065 单身狗 (25 分)
1065 单身狗 (25 分) “单身狗”是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ 50 000),是 ...
- 【PAT】B1070 结绳(25 分)
此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
随机推荐
- 51NOD 2026:Gcd and Lcm——题解
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=2026 参考及推导:https://www.cnblogs.com/ivo ...
- UVA.136 Ugly Numbers (优先队列)
UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...
- mysql 读写分离实现资料
以下很多链接需要 FQ才能看到,稍后会整理翻译成中文! Easy Read/Write Splitting with PHP’s MySQLnd https://blog.engineyard.com ...
- App.config的典型应用
----.net中XML的典型应用 第一种修改方式: 添加xml节点figguration内容, 微软提供了一种方案来读取connectionStrings里的内容 这样就可以拿到连接sql serv ...
- Mysql 语句优化技巧
前言 有人反馈之前几篇文章过于理论缺少实际操作细节,这篇文章就多一些可操作性的内容吧. 注:这篇文章是以 MySQL 为背景,很多内容同时适用于其他关系型数据库,需要有一些索引知识为基础. 优化目标 ...
- 【简单算法】18.实现strStr()
题目: 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始).如果不存 ...
- Test Index
top1 top11 top2 top1 top11 top2
- html 5 新特性
现在html 5技术是最新的html标准,掌握html 5已经变得非常重要,以下是我查看相关资料后对html 5 的新特性的总结,方便大家对比学习.html 5的新特性1.取消了一些过时的html 4 ...
- Android中禁止SlidingPaneLayout的侧滑功能
Android中使用android.support.v4.widget.SlidingPaneLayout实现侧滑功能的时候,可能出现滑动屏幕时与SlidingPaneLayout的侧滑发生冲突,查看 ...
- 增强学习Reinforcement Learning经典算法梳理3:TD方法
转自:http://blog.csdn.net/songrotek/article/details/51382759 博客地址:http://blog.csdn.net/songrotek/artic ...