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,存在则输出该学生排名最考前的一 ...
随机推荐
- appframework3.0(JQmobi)入门教程
2015-03-31 22:02 2011人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. appframework3.0好像是3月24日发布的,今天31号,发现和 ...
- jQuery之元素的遍历与元素的过滤
jQuery遍历之向下遍历 jQuery遍历之向上遍历 jQuery遍历之同级遍历 jQuery遍历之过滤
- was not declared in this scope
“was not declared in this scope”是一个错误信息,在编译的时候会遇到.其含义为标识符在其出现的地方是未被定义的. 出现该错误的时候,会同时把未定义的变量名显示出来.比如如 ...
- paper 132:图像去噪算法:NL-Means和BM3D
这篇文章写的非常好,确定要~认真~慎重~的转载了,具体请关注本文编辑作者:http://wenhuix.github.io/research/denoise.html 我不会告诉你这里的代码都是f ...
- win7,安装node失败
win7下,下载node安装包,安装之后 打开命令行输入 node -v,仍然提示命令不可用. 解决办法: 找到环境变量: 在用户变量里修改 path: 添加系统变量 NODE_PATH: 关机重启电 ...
- vsftpd.conf
引用:http://www.linuxidc.com/Linux/2012-08/67389.htm 研究嵌入式开发,开始使用的是Linux平台,用的是Ubuntu环境,但是发现Ubuntu的图形界面 ...
- 商品条形码(JBarcode)Java版(二)
下午开了一个下午的会议,其实开会我听不进去,因为今天妖都特别冷,下班在公司等待小媳妇一个钟头,然后带着她去吃饭,吃完饭回到家.她做运动,我就开始慢慢整理我自己的小博客. ——题记 先说一下,写这篇文章 ...
- WebSQL 查询工具
最近在写 WebSQL ,每次都在浏览器控制台执行 SQL 太费劲了,并且脑子不好使,总是忘记上次初始化的数据库是什么,所以写了一个特别简单的 WebSQL 可视化工具,说工具有点大了,就是为了方便, ...
- Java throws子句是怎么写的呢?
如果一个方法可以导致一个异常但不处理它,它必须指定这种行为以使方法的调用者可以保护它们自己而不发生异常.做到这点你可以在方法声明中包含一个throws子句.一个 throws 子句列举了一个方法可能抛 ...
- AngularJs的UI组件ui-Bootstrap---tabs控件
tabs控件使用uib-tabset指令和uib-tab指令,效果是这样的: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo ...