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 (≤), 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
Solution:
  排序而已,善于使用unordermap!
 #include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct Node
{
string id, school;
double tws;//切记,一定是double,每次PAT就是在这里下套
int score, nums, rank;
};
int main()
{
int n;
cin >> n;
vector<Node>v(n);
unordered_map<string, vector<int>>map;//记录相同学校的是哪些人
for (int i = ; i < n; ++i)
{
string name, school;
int score;
cin >> name >> score >> school;
for (int j = ; j < school.size(); ++j)
school[j] = tolower(school[j]);
v[i] = { name,school,0.0,score,, };
map[school].push_back(i);
}
vector<Node>res;
for (auto ptr = map.begin(); ptr != map.end(); ++ptr)
{
vector<int>p = ptr->second;
res.push_back({ "", v[p[]].school, 0.0, , (int)p.size(), });//将相同学校的分数相加
for (auto a : p)
{
if (v[a].id[] == 'A')
res.back().tws += v[a].score;
else if (v[a].id[] == 'B')
res.back().tws += v[a].score / 1.5;
else
res.back().tws += v[a].score * 1.5;
}
}
sort(res.begin(), res.end(), [](Node a, Node b) {//排名
if ((int(a.tws)) == (int(b.tws)) && a.nums == b.nums)
return a.school < b.school;
else if ((int(a.tws)) == (int(b.tws)))
return a.nums < b.nums;
else
return a.tws > b.tws;
});
cout << res.size() << endl;
for (int i = ; i < res.size(); ++i)
{
if (i > && ((int)res[i].tws) == ((int)res[i-].tws))
res[i].rank = res[i - ].rank;
else
res[i].rank = i + ;
cout << res[i].rank << " " << res[i].school << " " << (int)res[i].tws << " " << res[i].nums << endl;
}
return ;
}

PAT甲级——A1141 PATRankingofInstitution的更多相关文章

  1. PAT甲级——A1141 PATRankingofInstitution【25】

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  2. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  3. PAT甲级1131. Subway Map

    PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...

  4. PAT甲级1127. ZigZagging on a Tree

    PAT甲级1127. ZigZagging on a Tree 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...

  5. PAT甲级1123. Is It a Complete AVL Tree

    PAT甲级1123. Is It a Complete AVL Tree 题意: 在AVL树中,任何节点的两个子树的高度最多有一个;如果在任何时候它们不同于一个,则重新平衡来恢复此属性.图1-4说明了 ...

  6. PAT甲级1119. Pre- and Post-order Traversals

    PAT甲级1119. Pre- and Post-order Traversals 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二进制树可以通过给定的一对后序和顺序遍历序列来确定,也可以通 ...

  7. PAT甲级1114. Family Property

    PAT甲级1114. Family Property 题意: 这一次,你应该帮我们收集家族财产的数据.鉴于每个人的家庭成员和他/她自己的名字的房地产(房产)信息,我们需要知道每个家庭的规模,以及他们的 ...

  8. PAT甲级1111. Online Map

    PAT甲级1111. Online Map 题意: 输入我们当前的位置和目的地,一个在线地图可以推荐几条路径.现在你的工作是向你的用户推荐两条路径:一条是最短的,另一条是最快的.确保任何请求存在路径. ...

  9. PAT甲级1107. Social Clusters

    PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...

随机推荐

  1. JDK1.8 - > 1.7

    原文地址  https://blog.csdn.net/hwjean/article/details/52537722 JDK 1.8 -> 1.7 1. 配置好环境变量(我的是64bit系统) ...

  2. HBase最佳实践-读性能优化策略

    任何系统都会有各种各样的问题,有些是系统本身设计问题,有些却是使用姿势问题.HBase也一样,在真实生产线上大家或多或少都会遇到很多问题,有些是HBase还需要完善的,有些是我们确实对它了解太少.总结 ...

  3. Java空对象模式

    在“空对象”模式中,空对象将替换NULL对象实例的检查.而不是检查一个空值,Null对象反映一个无关的关系(即什么也不做). 这种Null对象还可以用于在数据不可用时提供默认行为. 在空对象模式(Nu ...

  4. Java并发AtomicIntegerArray类

    java.util.concurrent.atomic.AtomicIntegerArray类提供了可以以原子方式读取和写入的底层int数组的操作,还包含高级原子操作. AtomicIntegerAr ...

  5. linux 部署系统通过SecureCRT启动tomcat 控制台中文乱码

    查资料又是查了半天 首先 查看linux 当前系统字符集命令 echo $LANG 查看linux 当前系统语言 locale 网上说的又是下中文包,又是改临时语言,这些不能一概而论,我也觉得我不是中 ...

  6. webpack打包配置中出现的问题

    第一个错误: One CLI for webpack must be installed. These are recommended choices, delivered as separate p ...

  7. Https socket 代理

    https直接与服务器通过ssLsocket连接可行 import java.io.InputStream;import java.io.OutputStream;import java.securi ...

  8. SpringBoot集成Swagger,Postman,newman,jenkins自动化测试.

    环境:Spring Boot,Swagger,gradle,Postman,newman,jenkins SpringBoot环境搭建. Swagger简介 Swagger 是一款RESTFUL接口的 ...

  9. size - 列出段节大小和总共大小

    总览 (SYNOPSIS) size [-A|-B|--format=compatibility] [--help] [-d|-o|-x|--radix=number] [--target=bfdna ...

  10. go语言从例子开始之Example21.协程

    Go 协程 在执行上来说是轻量级的线程. golang使用协程用go关键字.后边正常调用函数. Example: package main import "fmt" func ak ...