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 (≤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, 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[难]的更多相关文章

  1. PAT 甲级 1141 PAT Ranking of Institutions

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

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

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

  3. 1141 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

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

  5. 1141 PAT Ranking of Institutions

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

  6. PAT_A1141#PAT Ranking of Institutions

    Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...

  7. A1141. PAT Ranking of Institutions

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

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

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

  9. PAT Ranking (排名)

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

随机推荐

  1. 一个try可以跟进多个catch语句,用于处理不同情况,当一个try只能匹配一个catch

    一个try可以跟进多个catch语句,用于处理不同情况.当一个try只能匹配一个catch. 我们可以写多个catch语句,但是不能将父类型的exception的位置写在子类型的excepiton之前 ...

  2. linux改动登陆主机提示信息

    寻常管理着130多台Linux物理主机.真正搞清楚每一台主机的IP信息.应用部署比較麻烦! 所以在部署之初,必须规划好: 写一个脚本.把主机IP.管理员联系方法,应用部署等主机信息放在.sh里面 sh ...

  3. XMPP客户端

    1. Strophe.js 2. Converse.js

  4. sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)

    Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...

  5. ios 开发之 -- UILabel的text竖行显示

    让UILabel的内容竖行显示,我经常用一下两种方式: 第一种:使用换行符 \n label.text = @"请\n竖\n直\n方\n向\n排\n列"; label.number ...

  6. Layui前后台交互数据获取java

    Layui简介 Layui是一款适用于后台程序员的UI框架,学习成本低.Json数据格式交互前后台,并且也相当适用单页面开发.有兴趣的朋友可以看看layui官网. Layui前后台数据交互 layui ...

  7. MFC中控件的TAB顺序

    本文来自: http://hi.baidu.com/qingcaichongch/item/47f7ae14de8cbef6ddeeca42 在MFC中添加控件后,按Ctrl+d可以改变控件TAB顺序 ...

  8. you *might* want to use the less safe log_bin_trust_function_creators variable

    报错:you *might* want to use the less safe log_bin_trust_function_creators variable 解决方法如下: 1. mysql&g ...

  9. java的list集合如何根据对象中的某个字段排序?

    转自:http://blog.csdn.net/wangjuan_01/article/details/51351633 List集合按某个字段排序 package wjtest_01; import ...

  10. protobuf在java应用中通过反射动态创建对象(DynamicMessage)

    ---恢复内容开始--- 最近编写一个游戏用到protobuf数据格式进行前后台传输,苦于protobuf接受客户端的数据时是需要数据类型的如xxx.parseForm(...),这样就要求服务器在接 ...