题目

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

题意

致谢:https://blog.csdn.net/liuchuo/article/details/79618766

给出每个学生的id、分数、学校,学校名称不区分大小写,输出学校排名、学校名称、总加权成绩、学校参赛人数。学校名称输出时候以小写方式输出。

分析

致谢:https://blog.csdn.net/liuchuo/article/details/79618766

1.两个unordered_map,一个用来存储某学校名称对应的参赛人数,另一个计算某学校名称对应的总加权成绩

2.对于排名的处理:设立pres表示前一个学校的加权总分,如果pres和当前学校的加权总分不同,说明rank等于数组下标+1,否则rank不变

陷阱

1.结果是截取的整数
计数的时候存浮点数,存到结果的时候就要截取成整数,输出的时候也是整数。这三个地方反过来一个都不行。

2.map会超时
1153同款操作,只能用unordered_map

3.排名
分、人数、代号都要参加排序,自己写排序函数

4.学校名要存小写
没有现成的转换库函数,要自己写

int j=0;
while(j<sn.size()){sn[j]=tolower(sn[j]);j++;
}

满分代码一

#include<iostream>
#include<vector>
#include<unordered_map>
#include<cctype>
using namespace std;
int n,m;
string si,sn;
struct school{string id;int score,number;
};
bool cmp(school &a,school &b){if(a.score!=b.score)return a.score>b.score;else if(a.number!=b.number) return a.number<b.number;else return a.id<b.id;
}
int main(){scanf("%d",&n);unordered_map<string,double> m1;unordered_map<string,int> m2;for(int i=0;i<n;i++){cin>>si>>m>>sn;int j=0;while(j<sn.size()){sn[j]=tolower(sn[j]);j++;}if(si[0]=='A')m1[sn]+=m;else if(si[0]=='B')m1[sn]+=m/1.5;else if(si[0]=='T')m1[sn]+=m*1.5;m2[sn]++;}vector<school> v;for(auto it:m1){v.push_back({it.first,(int)it.second,m2[it.first]});}printf("%d\n",v.size());sort(v.begin(),v.end(),cmp);int rank=1,total=1,pre=0;for(auto it:v){if(total==1){printf("1 %s %d %d\n",it.id.c_str(),it.score,it.number);}else{if(it.score==pre){printf("%d %s %d %d\n",rank,it.id.c_str(),it.score,it.number);}else {printf("%d %s %d %d\n",total,it.id.c_str(),it.score,it.number);rank=total;}}pre=it.score;total++;}return 0;
}

满分代码二(也可以用set+运算符重载来代替向量的排序)

#include<iostream>
#include<unordered_map>
#include<cctype>
#include<set>
using namespace std;
int n,m;
string si,sn;
struct school{string id;int score,number;bool operator < (const school &a) const{if(a.score!=score)return a.score<score;else if(a.number!=number) return a.number>number;else return a.id>id;}
};
set<school> s;
int main(){scanf("%d",&n);unordered_map<string,double> m1;unordered_map<string,int> m2;for(int i=0;i<n;i++){cin>>si>>m>>sn;for(int j=0;j<sn.size();j++) sn[j]=tolower(sn[j]);if(si[0]=='A')m1[sn]+=m;else if(si[0]=='B')m1[sn]+=m/1.5;else if(si[0]=='T')m1[sn]+=m*1.5;m2[sn]++;}for(auto it:m1){s.insert({it.first,(int)it.second,m2[it.first]});}printf("%d\n",s.size());int rank=1,total=1,pre=0;for(auto it:s){if(total==1){printf("1 %s %d %d\n",it.id.c_str(),it.score,it.number);}else{if(it.score==pre){printf("%d %s %d %d\n",rank,it.id.c_str(),it.score,it.number);}else {printf("%d %s %d %d\n",total,it.id.c_str(),it.score,it.number);rank=total;}}pre=it.score;total++;}return 0;
}

彩蛋

hpyu 哈佛大学、耶鲁大学和普林斯顿大学的合称

lanx 蓝翔

au 美利坚大学等好几所国外的大学/软件Au/金元素

pku 北京大学(陈越姥姥母校)

cmu 卡耐基梅隆大学

推荐阅读:2020年7月PAT甲级满分必备刷题技巧

17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼相关推荐

  1. 1141 PAT Ranking of Institutions (25 分)

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

  2. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  3. 19年冬季第二题 PAT甲级 1166 Summit (25分)

    7-3 Summit (25分) A summit (峰会) is a meeting of heads of state or government. Arranging the rest area ...

  4. 19年春季第二题 PAT甲级 1157 Anniversary(25 分)

    英文题目 Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the cel ...

  5. PAT甲级-1021 Deepest Root(25分)

    题目:1021 Deepest Root(25分) 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出 ...

  6. 19年冬季第二题 PAT甲级 1165 Block Reversing (25分) 跟1133类似的题目

    题目 Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K ...

  7. 18年春季第一题 PAT甲级 1144 The Missing Number (20分) 上限感很重要

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

  8. PAT甲级 -- 1007 Maximum Subsequence Sum (25 分)

    Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to ...

  9. 【PAT甲级 - 1028】List Sorting (25分)(模拟,排序)

    题干: Excel can sort records according to any column. Now you are supposed to imitate this function. I ...

最新文章

  1. FreeBSD下安装配置Hadoop集群(三)
  2. Androidstudio坑
  3. 利用互斥体阻断想哭蠕虫,实现联网升级
  4. 轻松几步搞定SSH连接Git配置
  5. 在python中是否可以使用if作为变量名_在Python中可以使用if 作为变量名_python使用符号 标示注释...
  6. 监控linux终端键盘输入,Linux内核实时监控键盘输入
  7. 数据库中字段随机添加汉字
  8. 简单网络管理协议SNMP
  9. 6-7Pytorch搭建cifar10训练脚本(上)
  10. mybatis防止sql注入
  11. mediawiki修改用mysql数据库_mysql – Mediawiki数据库恢复
  12. [摘文]BizTalk概述
  13. 很多的Adobe Dreamweaver CS5序列号
  14. 使用手册 煤矿风险管控系统_煤矿风险分级管控手册.doc
  15. 360插件化Replugin爬坑之路
  16. 软件导出excel时提示没有注册类
  17. 全量表/增量表/快照表
  18. 如何对图像进行卷积操作
  19. jQuery赋值checked的几种写法:
  20. Unity 安卓 apk 反编译 重新打包 签名修改

热门文章

  1. c语言机房管理系统答辩,C语言综合实验报告机房管理系统
  2. 3655: 网络禁用语
  3. “协作+服务”丨 智能工单如何实现企业高效管理?
  4. Ubuntu安装软件事出现依赖关系有问题解决方案
  5. mac中Typora+PicGo图床+gitee 保姆级教程
  6. 上海交通大学 计算机 复试,2020上海交通大学公共有初试复试考研经验
  7. 上海交通大学计算机科学好吗,上海交通大学计算机科学与技术考研难不难和研究生专业好不好...
  8. windows下powershell执行脚本报错
  9. Perl 数组应用详解(push, pop, shift, unshift)
  10. 民间秘术——防火知识