1141 PAT Ranking of Institutions[难]
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 (≤105), 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, Athe 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
题目大意:给出学生的id、分数、学校了,然后计算学校的相关排名,通过计算本考场内考生的等级分数,等最后按照一个规则排名。
//这个题确实挺麻烦的。
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
struct Sch{
int sb,sa,st;
int fin,stu;
string name;
Sch(string n){
name=n;
sb=;sa=;st=;stu=;}
void cal(){//但是如何取整数部分呢?如果直接赋值那应该是4舍5入的。
fin=sb/1.5+sa+st*1.5;
}
}; string lower(string s){
for(int i=;i<s.size();i++){
if(s[i]>='A'&&s[i]<='Z'){
s[i]=s[i]-'A'+'a';
}
}
return s;
} map<string,int> name2id;
vector<Sch> vsch; void add(string id,int index,int score){
if(id[]=='A')
vsch[index].sa+=score;
else if(id[]=='B')
vsch[index].sb+=score;
else vsch[index].st+=score;
} bool cmp(Sch& a,Sch& b){//排序函数。
if(a.fin>b.fin)return true;
else if(a.fin==b.fin&&a.stu<b.stu)return true;
else if(a.fin==b.fin&&a.stu==b.stu&&a.name<b.name)return true;
} int main() {
int n;
cin>>n;
string id,sh;
int sco,ct=;//ct表示有多少个学校。
for(int i=;i<n;i++){
cin>>id>>sco>>sh;
sh=lower(sh);//函数是如何转换大小写?
if(name2id.count(sh)==){//如果当前机构不存在的话
name2id[sh]=ct++;
vsch.push_back(Sch(sh));//把机构的名字传进去。
add(id,ct-,sco);
}else{//如果已经存在
int temp=name2id[sh];
add(id,temp,sco);
vsch[temp].stu++;//又多了一个学生。
}
}
int size=name2id.size();
cout<<size<<'\n';
//计算得分;
for(int i=;i<vsch.size();i++){
vsch[i].cal();
}
sort(vsch.begin(),vsch.end(),cmp);
int rank=;
for(int i=;i<size;i++){
if(i!=){
if(vsch[i].fin!=vsch[i-].fin)
rank++;//这时候排名才++;
//其他情况排名不++
}
cout<<rank<<" "<<vsch[i].name<<" "<<vsch[i].fin<<" "<<vsch[i].stu<<'\n'; }
return ;
}
wrong
//这个我写了将近一个小时,但是最终第一次提交结果如下:

真是心里凉凉,待会再看柳神的吧。
AC了:
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
struct Sch{
int sb,sa,st;
int fin,stu;
string name;
Sch(string n){
name=n;
sb=;sa=;st=;stu=;}
void cal(){//但是如何取整数部分呢?如果直接赋值那应该是4舍5入的。
fin=sb/1.5+sa+st*1.5;
}
}; string lower(string s){
for(int i=;i<s.size();i++){
if(s[i]>='A'&&s[i]<='Z'){
s[i]=s[i]-'A'+'a';
}
}
return s;
} map<string,int> name2id;
vector<Sch> vsch; void add(string id,int index,int score){
if(id[]=='A')
vsch[index].sa+=score;//都是int型的操作。
else if(id[]=='B')
vsch[index].sb+=score;
else vsch[index].st+=score;
} bool cmp(Sch& a,Sch& b){//排序函数。
if(a.fin>b.fin)return true;
else if(a.fin==b.fin&&a.stu<b.stu)return true;
else if(a.fin==b.fin&&a.stu==b.stu&&a.name<b.name)return true;
return false;
} int main() {
int n;
cin>>n;
string id,sh;
int sco,ct=;//ct表示有多少个学校。
for(int i=;i<n;i++){
cin>>id>>sco>>sh;
sh=lower(sh);//函数是如何转换大小写?
if(name2id.count(sh)==){//如果当前机构不存在的话
name2id[sh]=ct++;
vsch.push_back(Sch(sh));//把机构的名字传进去。
add(id,ct-,sco);
}else{//如果已经存在
int temp=name2id[sh];
add(id,temp,sco);
vsch[temp].stu++;//又多了一个学生。
}
}
int sz=name2id.size();
cout<<sz<<'\n';
//计算得分;
for(int i=;i<vsch.size();i++){
vsch[i].cal();
}
sort(vsch.begin(),vsch.end(),cmp);
int rank=;
for(int i=;i<sz;i++){
if(i!=){
if(vsch[i].fin!=vsch[i-].fin)
rank=i+;//这时候排名才++;
//其他情况排名不++
}
cout<<rank<<" "<<vsch[i].name<<" "<<vsch[i].fin<<" "<<vsch[i].stu<<'\n'; }
return ;
}
1.在最终输出排名时,一开始写的rank++,明显不对,而应该是rank=i+1才对!
2.另外非常重要的是这个cmp函数里,最后一定要有一个return false,不然会出大问题!
3.tolower函数是对单个char来使用的。
1141 PAT Ranking of Institutions[难]的更多相关文章
- PAT 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- [PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- 1141 PAT Ranking of Institutions (25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT 1141 PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- 1141 PAT Ranking of Institutions
题意:给出考生id(分为乙级.甲级和顶级),取得的分数和所属学校.计算各个学校的所有考生的带权总成绩,以及各个学校的考生人数.最后对学校进行排名. 思路:本题的研究对象是学校,而不是考生!因此,建立学 ...
- PAT_A1141#PAT Ranking of Institutions
Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...
- A1141. PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT Ranking (排名)
PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...
随机推荐
- MySQL Python教程(2)
mysql官网关于python的API是最经典的学习材料,相信对于所有函数浏览一遍以后,Mysql数据库用起来一定得心应手. 首先看一下Connector/Python API包含哪些类和模块. Mo ...
- Differential Geometry之第七章曲面的若干整体性质
1.曲面的整体描述 2.整体的Gauss-Bonnet公式 2.1.曲面的三角剖分 2.2.Gauss-Bonnet公式 = 2.3.Gauss-Bonnet定理的应用 2.3.1.切向量场的指数定理 ...
- linux -- 查看ip,路由,dns
查看ip地址:ifconfig 查看gateway:route 查看dns:nm-tool
- HDU1717--小数化分数2
这道题是将输入的小数(有可能是无限循环小数)来化为分数.刚開始看到以为枚举(千万不要嘲笑我),可是感觉不正确. 所以百度了小数化为分数的方法,然后看到了各种方法,原来是这这样,在这我採用的是小数化为分 ...
- bundle安装方法
sudo chmod +x filename.bundle sudo ./filename .bundle 原文链接:http://www.chinastor.com/a/linux/ubuntu/0 ...
- java 问题
1. 在ezmorph包中 有个 引用类时 写法为import [Z; 为什么加个[看不懂
- Administrator privileges required for OLE Remote Procedure Call debugging: this feature will not work..
VC++ 6.0单步调试(F10)出现警告框: 解决方法: 右键VC++ 6.0程序图标
- CreateRemoteThreadex开启远程线程失败集合
修改进程PE头 报错 修改进程_EPROCESS +0x12c SectionBaseAddress : 0x00bf0000 都会报错 不是有效的win32程序 错误号193 修改进程PEB +0x ...
- 后Hadoop时代的大数据架构
提到大数据分析平台,不得不说Hadoop系统,Hadoop到现在也超过10年的历史了,很多东西发生了变化,版本也从0.x进化到目前的2.6版本.我把2012年后定义成后Hadoop平台时代,这不是说不 ...
- 【BZOJ4606】[Apio2008]DNA DP
[BZOJ4606][Apio2008]DNA Description 分析如DNA序列这样的生命科学数据是计算机的一个有趣应用.从生物学的角度上说,DNA 是一种由腺嘌呤.胞嘧啶.鸟嘌呤和胸腺嘧啶这 ...