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, 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
题目大意:给出学生的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 ...
随机推荐
- Toad 所有 菜单说明(太多)
菜单说明 新版本 toad 软件中, 比较有用的菜单 session 菜单 Session Information: 显示当前session的用户的情况, 比如权限, 授权等 Database ...
- 8天学通MongoDB(mark)
转自:http://www.cnblogs.com/huangxincheng/archive/2012/02/18/2356595.html 关于mongodb的好处,优点之类的这里就不说了,唯一要 ...
- @Bean 小知识
先说结论 @Bean 可以用在任意方法上. -- 也可以用在注解上面. @Bean 仅在Spring创建bean时起作用. 这应该算一个小技巧,在一个平常类(非@Configuration class ...
- MD5的各种实现——也是醉了
MD5即Message-Digest Algorithm 5(信息-摘要算法5).用于确保信息传输完整一致. 是计算机广泛使用的杂凑算法之中的一个(又译摘要算法.哈希算法),主流编程语言普遍已有MD5 ...
- C#正则表达式操作中使用LINQ
比如:[程序员][代码]博客园 - 程序员的网上家园,代码改变世界 提取出来的Tag应该是:[程序员].[代码] Regex _regexTag = new Regex(@"^(\[[^\] ...
- Unity中对SQL数据库的操作
在Unity中,我们有时候需要连接数据库来达到数据的读取与储存.而在.NET平台下,ADO.NET为我们提供了公开数据访问服务的类.客户端应用程序可以使用ADO.NET来连接到数据源,并查询,添加,删 ...
- M451例程讲解之按键
/**************************************************************************//** * @file main.c * @ve ...
- Linux网络流量控制工具—Netem
第一篇:概念篇 Netem 是 Linux 2.6 及以上内核版本提供的一个网络模拟功能模块.该功能模块可以用来在性能良好的局域网中,模拟出复杂的互联网传输性能,诸如低带宽.传输延迟.丢包等等情况.使 ...
- java后台高德经纬度转地理位置信息
import java.util.LinkedList;import java.util.List; import org.apache.http.HttpResponse;import org.ap ...
- PHP 基础知识代码总结
一.PHP基础语法 变量到数组 <?php //phpinfo(); /* 变量 $a=1;//不分配空间 echo "\$a=".$a; echo "<br ...