Source:

PAT A1141 PAT Ranking of Institutions (25 分)

Description:

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

Keys:

  • map(C++ STL)
  • string(C++ STL)
  • 快乐模拟

Attention:

  • 字符串转换为小写:transform(s.begin(),s.end(),s.begin(),::tolower);
  • 字符串转换为大写:transform(s.begin(),s.end(),s.begin(),::toupper);
  • 分数用double存储,比较总分时再取整数部分,若计算各个Int再相加,会有误差
  • cmp,rank,printf,三处的比分都要用整数,各对应一个测试点

Code:

 /*
Data: 2019-08-06 20:19:45
Problem: PAT_A1141#PAT Ranking of Institutions
AC: 33:40 题目大意:
按分数排名
输入:
第一行给出,考试人数N<=1e5
接下来N行给出,ID(1位字母+5位数字),分数[0,100],学校(<=6,大小写敏感)
输出:
第一行输出,学校总数M
接下来M行,排名(>=1), 学校(小写),总分(B/1.5+A+T*1.5),考生数
排序规则,总分递减,人数递增,学校字典序
*/
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e5+;
int pos=;
map<string,int> mp;
struct node
{
string sch;
double score;
int num;
}ans[M]; int Hash(string s)
{
if(mp[s]==)
{
ans[pos]=node{s,,};
mp[s]=pos++;
}
return mp[s];
} bool cmp(const node &a, const node &b)
{
if((int)a.score != (int)b.score)
return a.score > b.score;
else if(a.num != b.num)
return a.num < b.num;
else
return a.sch < b.sch;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
scanf("%d", &n);
for(int i=; i<n; i++)
{
string id,sc;
double grade;
cin >> id >> grade >> sc;
transform(sc.begin(),sc.end(),sc.begin(),::tolower);
int pt = Hash(sc);
if(id[]=='T') grade *= 1.5;
if(id[]=='B') grade /= 1.5;
ans[pt].score += grade;
ans[pt].num++;
}
sort(ans+,ans+pos,cmp);
int r=;
printf("%d\n", pos-);
for(int i=; i<pos; i++)
{
if(i!= && (int)ans[i-].score != (int)ans[i].score)
r=i;
printf("%d %s %d %d\n", r,ans[i].sch.c_str(),(int)ans[i].score,ans[i].num);
} return ;
}

PAT_A1141#PAT Ranking of Institutions的更多相关文章

  1. 1141 PAT Ranking of Institutions[难]

    1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...

  2. A1141. PAT Ranking of Institutions

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

  3. PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化

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

  4. PAT 甲级 1141 PAT Ranking of Institutions

    https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...

  5. [PAT] 1141 PAT Ranking of Institutions(25 分)

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

  6. 1141 PAT Ranking of Institutions (25 分)

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

  7. PAT 1141 PAT Ranking of Institutions

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

  8. 1141 PAT Ranking of Institutions

    题意:给出考生id(分为乙级.甲级和顶级),取得的分数和所属学校.计算各个学校的所有考生的带权总成绩,以及各个学校的考生人数.最后对学校进行排名. 思路:本题的研究对象是学校,而不是考生!因此,建立学 ...

  9. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

随机推荐

  1. Spring MVC的@RequestMapping多个URL映射到同一个方法

    @RequestMapping可以是一个URL对应一个方法,也可以多个URL对应同一个方法,写法如下: @RequestMapping(value={"url","res ...

  2. Spring MVC-集成(Integration)-生成RSS源示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_rss_feed.htm 说明:示例基于Spring MVC 4.1.6. 以下示 ...

  3. Android:开机自启动并接收推送消息

    接收推送消息部分我们通过ZeroMQ实现,可以参考http://www.cnblogs.com/ilovewindy/p/3984283.html. 首先是开机自启动的功能实现,代码如下:1.     ...

  4. Android:创建ZeroMQ的客户端

    这里我们将给出一个subscribe模式的客户端示例程序,如下: private class ZeroMQMessageTask extends AsyncTask<String, Void, ...

  5. password加密的算法

    加密原理:採用不同的加密算法对字符串进行加盐加密处理. 用以防止密文被md5字典进行反向暴力破解. 採用美国家安全局发布的加密算法(RFC 4357)加密,不採用自己创建的加密算法,以避免有安全漏洞. ...

  6. hdu1068 Girls and Boys --- 最大独立集

    有一个集合男和一个集合女,给出两集合间一些一一相应关系.问该两集合中的最大独立集的点数. 最大独立集=顶点总数-最大匹配数 此题中.若(a,b)有关.则(b,a)有关.每个关系算了两次,相当于二分图的 ...

  7. cannot find -l****问题的解决的方法

    在ubuntu下编译C或cpp文件时,可能会出现找不到链接库的问题,其形式为: cannot find -l**** 这里的**通常是指的链接库.比方,刚刚装好opencv,依照网上教程一步步编译好了 ...

  8. BNU 13289 Energetic Pandas DP

     Energetic Pandas  There are n bamboos of different weights Wi. There are n pandas of different capa ...

  9. ride关键字

    定义变量:set variable 打印 :log 列表:create list 字符转数字型:evaluate 随机数:evaluate random.randint 日志截图:先导入screens ...

  10. Chrome 最小化恢复之后部分黑屏

    解决办法:设置->显示高级设置->关闭硬件加速