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 分)的更多相关文章

  1. PAT乙级:1090危险品装箱(25分)

    PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清 ...

  2. PAT乙级:1070 结绳 (25分)

    PAT乙级:1070 结绳 (25分) 题干 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟 ...

  3. PAT 1141 PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  4. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  5. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  6. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  7. PAT 乙级 1065 单身狗 (25 分)

    1065 单身狗 (25 分) “单身狗”是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ 50 000),是 ...

  8. 【PAT】B1070 结绳(25 分)

    此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...

  9. PAT甲级——1130 Infix Expression (25 分)

    1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...

随机推荐

  1. 洛谷 P1841 [JSOI2007]重要的城市 解题报告

    P1841 [JSOI2007]重要的城市 题目描述 参加jsoi冬令营的同学最近发现,由于南航校内修路截断了原来通向计算中心的路,导致去的路程比原先增加了近一公里.而食堂门前施工虽然也截断了原来通向 ...

  2. HDOJ.1228 A + B (map)

    A + B 点我挑战题目 点我一起学习STL-MAP 题意分析 讲字符串和数字用map对应即可 代码总览 /* Title:HDOJ.1228 Author:pengwill Date:2016-11 ...

  3. [学习笔记]Segment Tree Beats!九老师线段树

    对于这样一类问题: 区间取min,区间求和. N<=100000 要求O(nlogn)级别的算法 直观体会一下,区间取min,还要维护区间和 增加的长度很不好求.... 然鹅, 从前有一个来自杭 ...

  4. selenium测试-open chrome

    通过selenium来打开浏览器测试之前,需要确认本地已安装相应的webdriver,本例以chrome为例. 1. 查看本地chrome版本,以此确认需要安装的webdriver版本 查看chrom ...

  5. bzoj1529 [POI2005]ska Piggy banks 并查集

    [POI2005]ska Piggy banks Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1508  Solved: 763[Submit][Sta ...

  6. Leetcode 557. 反转字符串中的单词 III

    1.题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" ...

  7. sql service 事务与锁

    了解事务和锁 事务:保持逻辑数据一致性与可恢复性,必不可少的利器. 锁:多用户访问同一数据库资源时,对访问的先后次序权限管理的一种机制,没有他事务或许将会一塌糊涂,不能保证数据的安全正确读写. 死锁: ...

  8. NOIP2006 数列

    codevs 1141 数列 http://codevs.cn/problem/1141/ 2006年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB     题目描述  ...

  9. Matlab 工具箱介绍

    Toolbox工具箱 序号 工具箱 备注 数学.统计与优化 1 Symbolic Math Toolbox 符号数学工具箱 2 Partial Differential Euqation Toolbo ...

  10. 图论:Prufer编码-Cayley定理

    BZOJ1430:运用Cayley定理解决树的形态统计问题 由Prufer编码可以引申出来一个定理:Cayley 内容是不同的n结点标号的树的数量为n^(n-2) 换一种说法就是一棵无根树,当知道结点 ...