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. 【BZOJ】1005: [HNOI2008]明明的烦恼(prufer编码+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1005 这里讲得挺清楚的:http://www.cnblogs.com/zhj5chengfeng/p ...

  2. PHPExcel IE导出乱码问题

    引用改网站介绍:http://blog.chinaunix.net/uid-22414998-id-113450.html PHPExcel是微软认证的一个PHP操作Excel表格的类库,功能强大,所 ...

  3. ios开发之--UIWebView全属性

    最近的项目当中需要用到html和ios的交互,所以就凑空整理一下,所有webView相关的方法和属性,如有不对的地方,请大家不吝指教! 代码如下: 1,创建webview并设置代理 UIWebView ...

  4. 修改UE4的deriveddatacache目录位置,扩大C盘空间

    按照默认安装目录,UE4会装在C盘 C:\Program Files\Epic Games\UE_4.15 DerivedDataCache缓存目录在 C:\Users\你的用户名\AppData\L ...

  5. recyclerView中的方法

    onCreateViewHolder(); onBindViewHolder(); getItemCount(); recyclerVIew中没有添加头布局和尾布局方法.可以用getItemViewT ...

  6. Java知识点梳理——集合

    1.定义:Java集合类存放于java.util包,是存放对象的容器,长度可变,只能存放对象,可以存放不同的数据类型: 2.常用集合接口: a.Collection接口:最基本的集合接口,存储不唯一, ...

  7. [Web] 如何实现Web服务器和应用服务器的负载均衡?

    本文对Web服务器和应用服务器的负载均衡进行说明. 在负载均衡的思路下,多台服务器为对称方式,每台服务器都具有同等的地位,可以单独对外提供服务而无须其他服务器的辅助.通过负载分担技术,将外部发送来的请 ...

  8. 【BZOJ3033】太鼓达人 暴力+欧拉回路

    [BZOJ3033]太鼓达人 Description 七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行.这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是刚刚被精英队伍成员 ...

  9. python3个人习惯的gitignore

    简介 就是普通的.gitignore # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C ext ...

  10. Java基础之MySQL数据库与JDBC

    一.数据库 DBMS         数据库管理系统 是由多个程序构成的专门用来管理大量数据的计算机系统 Server       提供数据存储.检索.计算等服务的网络程序+系统服务 Notifier ...