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. C#读取EXECL关键代码

    string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extend ...

  2. 《javascript征途》学习笔记

    基础 1. 只有函数有作用域 2. 如果在<script src>的src 中设置了src特性,则script元素包含的任意代码就无效了.应该分开放到不同的script块中. 3. 外部j ...

  3. C++ 类的深拷贝和浅拷贝完美解决

    //类的深拷贝和浅拷贝 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class Poin ...

  4. 第二百六十八节,Tornado框架-路由映射之二级域名支持,html模板继承以及导入

    Tornado框架-路由映射之二级域名支持,html模板继承以及导入 二级域名路由映射add_handlers()设置二级域名路由映射 注意:二级域名需要结合服务器ip绑定域名 框架引擎 #!/usr ...

  5. Myeclipse怎么导入project项目

    1,打开Meclipse,在左面的区域点击右键,选择import键. 2,在import面板中选择Exiting Projects into Workbence,点击Next, 3,选择Browse. ...

  6. 理解javascript函数调用和“this”

    http://blog.csdn.net/littlechang/article/details/8180550

  7. 如何让listview滚动到底部

    方法一: // msgListView是ListView控件 // adapter是ListView绑定的Adapter,如果不方便直接使用,也可以通过ListView的getAdapter()方法获 ...

  8. Android 将时间戳转为代表"距现在多久之前"的字符串

    public String getStandardDate(int dateTime) { StringBuffer sb = new StringBuffer(); long t = Long.pa ...

  9. Spring的AOP细节理解

    什么是AOP?AOP:是面向切面编程,是对面向对象编程(oop)的一种补充,为什么需要AOP?例如在我们做一个计算器,要求我们每次运行对应的功能(也就是进行运算时)都要输出日志,以便于知道程序是怎么运 ...

  10. Struts2中的拦截器详解

    exception:异常拦截器,拦截异常aliasservletConfig18nprepare:预备拦截器,这个拦截器就是为了ModelDriven准备对象的,若Action类实现了preparab ...