PAT 1012. The Best Rank
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 Algrbra), 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
// 1012pat1.cpp : 定义控制台应用程序的入口点。
//
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std; const int INF=0x7fffffff;
struct Edge
{
string id;
int C,M,E,A;
}; struct R
{
int r;
char c;
bool flag;
R(){r=INF;c='A';flag=false;}
}; class TA:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.A>rhs.A;
}
};
class TC:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.C>rhs.C;
}
};
class TM:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.M>rhs.M;
}
};
class TE:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.E>rhs.E;
}
};
int main()
{
int n,m;
while(cinf>>n>>m)
{
Edge temp;
vector<Edge> vec;
map<string,R> rp;
for(int i=;i<=n;++i)
{
cinf>>temp.id>>temp.C>>temp.M>>temp.E;
rp[temp.id].flag=true;
temp.A=(temp.C+temp.M+temp.E)/;
vec.push_back(temp);
}
sort(vec.begin(),vec.end(),TA());
int rank=;
int cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->A==(iter+)->A)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='A';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='A';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='A';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='A';
}
}
}
sort(vec.begin(),vec.end(),TC());
rank=;
cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->C==(iter+)->C)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='C';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='C';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='C';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='C';
}
}
}
sort(vec.begin(),vec.end(),TM());
rank=;
cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->M==(iter+)->M)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='M';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='M';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='M';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='M';
}
}
}
sort(vec.begin(),vec.end(),TE());
rank=;
cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->E==(iter+)->E)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='E';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='E';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='E';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='E';
}
}
}
string id;
for(int i=;i<=m;++i)
{
cinf>>id;
if(rp[id].flag==true)
cout<<rp[id].r<<" "<<rp[id].c<<endl;
else
cout<<"N/A"<<endl;
}
}
return ;
}
PAT 1012. The Best Rank的更多相关文章
- PAT 1012 The Best Rank 排序
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT甲级1012. The Best Rank
PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...
- 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 ...
- PAT 1012
1012. The Best Rank (25) To evaluate the performance of our first year CS majored students, we consi ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 1012 The Best Rank (25 分)
1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...
- 1012 The Best Rank
1012 The Best Rank 1. 注意点 一名同学同样排名下的科目优先级问题 不同同学分数相同时排名相同,注意 排名不是 1 1 2 3 4 这种, 而是 1 1 3 4 5 注意到有些同学 ...
- 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 ...
随机推荐
- 设置Android程序的默认安装位置
修改 AndroidManifest.xml 文件: <manifest xmlns:android="http://schemas.android.com/apk/res/andro ...
- stream_context_create解决file_get_contents超时处理
stream_context_create作用:创建并返回一个文本数据流并应用各种选项,可用于fopen(),file_get_contents()等过程的超时设置.代理服务器.请求方式.头信息设置的 ...
- STM32系列命名规则
转自:STM32系列命名规则 STM32 F 103 C 6 T 7 xxx 1 2 3 4 5 6 7 8 第1部分:产品系列名,固定为STM32 第2部分:产品类型:F表示这是Flash产品,目前 ...
- POJ 3122 Pie 二分枚举
题目:http://poj.org/problem?id=3122 这个题就好多了,没有恶心的精度问题,所以1A了.. #include <stdio.h> #include <ma ...
- ASP.NET注意事项
1.服务器上bin目录下面的dll备份的时候,第一个点号之前的名字不能是一样的,否则会报错. 2.
- UIImage拉伸显示
下面张图片,是设计来做按钮背景的: button.png,尺寸为:24x60 现在我们把它用作为按钮背景,按钮尺寸是150x50,以下是没有经过技术性拉伸处理的情况: // 得到view的尺寸 ...
- 转:我们是否应该把后端构建为API
原文来自于:http://www.infoq.com/cn/news/2015/07/api-or-not 不久前,在StackExchange网站上,一位名为SLC的用户提起他正在设计一个ASP.N ...
- 二分法查找(Binary Search)
--摘要:二分法的介绍已经很多了,但并不直观,因此此文诞生,希望批评指正. 二分查找是在有序数组中查找一个元素的算法,通过比较目标元素与数组中间元素来查找,如果目标值是中间元素则将返回中间元素位置. ...
- [JavaScript] js 复制到剪切板
zeroclipboard官网:https://github.com/zeroclipboard/ZeroClipboard 下载压缩包,得到两个“ZeroClipboard.js”和“ZeroCli ...
- bzoj 3328: PYXFIB 数论
3328: PYXFIB Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 130 Solved: 41[Submit][Status][Discuss ...