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 ...
随机推荐
- 【WPF】Dispatcher及线程操作
WPF 应用程序启动后,会有两个线程: 1. 一个是用来处理UI呈现(处理UI的请求,比如输入和展现等操作). 2. 一个用来管理 UI的 (对UI元素及整个UI进行管理). 像Winform一样,W ...
- STM32系列命名规则
转自:STM32系列命名规则 STM32 F 103 C 6 T 7 xxx 1 2 3 4 5 6 7 8 第1部分:产品系列名,固定为STM32 第2部分:产品类型:F表示这是Flash产品,目前 ...
- 从IT的角度思考BIM(二):模式与框架
我们满怀着美好期许,鼓起勇气敲响了 BIM 世界的大门.忽然人群中有人高呼:BIM 已死,大家都散了吧! 这时人群开始骚动起来.“我早就说这玩意是忽悠人的吧,你们不信还偏要来”,“我花了好多钱准备这次 ...
- UI控件切圆角
1. xib下设置View圆角 这个很简单, 只需要重写 - (void)drawRect:(CGRect)rect 方法就行了 1 2 3 4 5 6 - (void)drawRect:(CGRe ...
- Java编程规范整理
分享一份网友整理的编程过程中的命名规范 包命名 包名按照域名的范围从大到小逐步列出,恰好和Internet上的域名命名规则相反. 由一组以"."连接的标识符构成,通常第一个标识符为 ...
- iOS开发UI基础—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
- X86汇编快速入门
http://www.cnblogs.com/YukiJohnson/archive/2012/10/27/2741836.html
- windows笔记-一个简单的windows GUI应用程序
#include<windows.h> // 编写Windows程序必须包含的头文件 LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); ...
- 使用AspNetPager与GridView完成分页
使用AspNetPager与GridView完成分页 由于GridView的分页功能实在是太弱了,所以需要使用强大的AspNetPager来作为分页控件.最简单的办法就是GridView控件下面接 ...
- Ubuntu下安装Qt4.5(包括X86和ARM版本)
条件:TQ2440开发板,虚拟机安装的Ubuntu10.04,安装好天嵌自带的GCC交叉编译器参考:http://blog.csdn.net/newnewman80/article/details/6 ...