1012. The Best Rank (25)
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C, M, E and A - Average of 4 students are given as the following:
StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.
Input
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.
Output
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output "N/A".
Sample Input
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
Sample Output
1 C
1 M
1 E
1 A
3 A
N/A 题目不难,就是自己代码写的好渣..
就有一个情况第一次没考虑到,就是出现相同排名的时候,修改后就过了
#include <iostream>
#include <map>
#include <cstdio> using namespace std; typedef struct Student{
string ID;
int c;
int m;
int e;
int a;
}Student; Student s[];
string CID[];
map<string,int> a;
map<string,int> c;
map<string,int> m;
map<string,int> e; int main()
{
int n,k;
char t;
cin>>n>>k;
for(int i=;i<n;i++){
cin>>s[i].ID>>s[i].c>>s[i].m>>s[i].e;
s[i].a=(s[i].c+s[i].m+s[i].e)/;
}
Student temp;
for(int i=;i<n;i++){
for(int j=i;j<n;j++){
if(s[i].a<s[j].a){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
a[s[].ID]=;
for(int i=;i<n;i++){
if(s[i].a==s[i-].a) a[s[i].ID]=a[s[i-].ID];
else a[s[i].ID]=i+;
} for(int i=;i<n;i++){
for(int j=i;j<n;j++){
if(s[i].c<s[j].c){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
c[s[].ID]=;
for(int i=;i<n;i++){
if(s[i].c==s[i-].c) c[s[i].ID]=c[s[i-].ID];
else c[s[i].ID]=i+;
} for(int i=;i<n;i++){
for(int j=i;j<n;j++){
if(s[i].m<s[j].m){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
m[s[].ID]=;
for(int i=;i<n;i++){
if(s[i].m==s[i-].m) m[s[i].ID]=m[s[i-].ID];
else m[s[i].ID]=i+;
} for(int i=;i<n;i++){
for(int j=i;j<n;j++){
if(s[i].e<s[j].e){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
e[s[].ID]=;
for(int i=;i<n;i++){
if(s[i].e==s[i-].e) e[s[i].ID]=e[s[i-].ID];
else e[s[i].ID]=i+;
} for(int i=;i<k;i++){
cin>>CID[i];
} for(int i=;i<k;i++){
int min=;
if (a.count(CID[i])==) {cout<<"N/A"<<endl;}
else{
if(a[CID[i]]<min) {min=a[CID[i]];t='A';}
if(c[CID[i]]<min) {min=c[CID[i]];t='C';}
if(m[CID[i]]<min) {min=m[CID[i]];t='M';}
if(e[CID[i]]<min) {min=e[CID[i]];t='E';}
cout<<min<<" "<<t<<endl;
}
} return ;
}
1012. The Best Rank (25)的更多相关文章
- PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏
1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 1012 The Best Rank (25分) vector与结构体排序
1012 The Best Rank (25分) To evaluate the performance of our first year CS majored students, we con ...
- 【PAT】1012. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
- 1012 The Best Rank (25)(25 point(s))
problem To evaluate the performance of our first year CS majored students, we consider their grades ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- 1012 The Best Rank (25 分)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT (Advanced Level) 1012. The Best Rank (25)
简单排序题. 注意:分数相同的人排名相同. #include<iostream> #include<cstring> #include<cmath> #includ ...
- PAT甲题题解-1012. The Best Rank (25)-排序水题
排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...
- 【PAT甲级】1012 The Best Rank (25 分)
题意: 输入两个整数N,M(<=2000),接着分别输入N个学生的ID,C语言成绩,数学成绩和英语成绩. M次询问,每次输入学生ID,如果该ID不存在则输出N/A,存在则输出该学生排名最考前的一 ...
随机推荐
- 使用EF Oracle实现DevExpress绑定大数据的ServerMode模式
前提:需要引入EntityFramework组件,注意几个使用点后使用上其实比较简单. 一.引入Oracle EF支持组建 1.可手动引入附件中的DLL(需手动合并web.config配置) 2.也可 ...
- mac系统terminal连接linux
ssh user@hostname user是管理员账号 hostname是服务器ip
- svg学习(九)path
<path> 标签用来定义路径. 下面的命令可用于路径数据: M = moveto L = lineto H = horizontal lineto V = vertical lineto ...
- jdbc 数据的增删改查的Statement Resultset PreparedStatement
完成数据库的连接,就马上要对数据库进行增删改查操作了:先来了解一下Statement 通过JDBC插入数据 (这里提供一个查找和插入方法) Statement:用于执行sql语句的对象: *1.通过C ...
- mysql 日期加减操作
1. MySQL 为日期增加一个时间间隔:date_add() set @dt = now(); select date_add(@dt, interval 1 day); -- add ...
- IP地址数据库-ISP运营商列表(2017年1月)
IP地址数据库 微信号:qqzeng-ip [全球旗舰版][国内精华版][国外拓展版][英文版][掩码版] http://qqzeng.com 中国大陆:三大基础运营商 中国电信中国联通中国 ...
- python学习笔记之基础二(第二天)
1.编码转换介绍 unicode是最底层.最纯的,会根据终端的编码进行转化展示 一般硬盘存储或传输为utf-8(因为省空间.省带宽),读入内存中为unicode,二者如何转换 a = ' ...
- vs打开项目出现“尚未配置为Web项目XXXX指定的本地IIS URL HTTP://localhost:…… .要打开此项目,需要配置虚拟目录……”提示
今天打开网上下载的一个源码,出现如标题的这个问题,这是从未遇见的提示.尝试点击是,但是网站还是运行不起来.于是网上搜索,就有了这篇. 解决的方案如下: 注意:也可以用记事本把工程文件(.vcxproj ...
- MaxScale:实现MySQL读写分离与负载均衡的中间件利器
1. MaxScale 是干什么的? 配置好了 MySQL 的主从复制结构后,我们希望实现读写分离,把读操作分散到从服务器中,并且对多个从服务器能实现负载均衡. 读写分离和负载均衡 是MySQL集群的 ...
- 关于访问链接返回XML的获取数据
1. 返回DataSet格式; /// <summary> /// 向某个url提交数据并读取该地址返回的xml,并将xml转换成dataset,并返回dataset中某个表 /// &l ...