1012. The Best Rank (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

提交代码

注意点:

1.题目先给出n个学生的情况,先对这n个学生按照A、C、M、E的顺序依次进行排序,按照题意得到每个学生最好的排名情况,存储下来。然后,查询m个学生,如果学生不存在,则输出“N/A”,否则,输出最好排名及对应A、C、M、E的哪种情况。

2.题目中如果排名是1 2 2 4 5 6 6 8规则排名(见代码),却不是1 2 2 3 4 5 5 6

3.map的使用:

http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html

添加元素:

map<int ,string> maplive;

1)maplive.insert(pair<int,string>(102,"aclive"));
2)maplive.insert(map<int,string>::value_type(321,"hai"));
3)maplive[112]="April";                      //map中最简单最常用的插入添加!

查找元素:

find()函数返回一个迭代器指向键值为key的元素,如果没找到就返回指向map尾部的迭代器。

map<int ,string >::iterator l_it;; 
l_it=maplive.find(112);
if(l_it==maplive.end())
               
cout<<"we do not find 112"<<endl;
else
cout<<"wo find 112"<<endl;

删除元素:

map<int ,string >::iterator l_it;
l_it=maplive.find(112);
if(l_it==maplive.end())
       
cout<<"we do not find 112"<<endl;
else  maplive.erase(l_it);    //删除元素

 #include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
struct cnode{
int grade;
string id;
};
struct mnode{
int grade;
string id;
};
struct enode{
int grade;
string id;
};
struct anode{
int grade;
string id;
};
struct somenode{
int rank;
string r;
};
map<string,somenode> some;
bool cmpa(anode a,anode b){
return a.grade>b.grade;
}
bool cmpc(cnode a,cnode b){
return a.grade>b.grade;
}
bool cmpm(mnode a,mnode b){
return a.grade>b.grade;
}
bool cmpe(enode a,enode b){
return a.grade>b.grade;
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,m,cg,mg,eg;
string num;
scanf("%d %d",&n,&m);
anode *ap=new anode[n];
cnode *cp=new cnode[n];
mnode *mp=new mnode[n];
enode *ep=new enode[n];
int i;
for(i=;i<n;i++){
cin>>num;
scanf("%d %d %d",&cg,&mg,&eg);
ap[i].id=ep[i].id=cp[i].id=mp[i].id=num;
ap[i].grade=int((cg+mg+eg)*1.0/+0.5); //四舍五入
ep[i].grade=eg;
mp[i].grade=mg;
cp[i].grade=cg;
} sort(ap,ap+n,cmpa);
int cal=;
somenode p;
p.r="A";
p.rank=cal;
some[ap[].id]=p;
for(i=;i<n;i++){
if(ap[i].grade!=ap[i-].grade){
cal=i+;
}
p.r="A";
p.rank=cal;
some[ap[i].id]=p;
} sort(cp,cp+n,cmpc);
cal=;
if(some[cp[].id].rank>cal){
some[cp[].id].rank=cal;
some[cp[].id].r="C";
}
for(i=;i<n;i++){
if(cp[i].grade!=cp[i-].grade){
cal=i+;
}
if(some[cp[i].id].rank>cal){
some[cp[i].id].rank=cal;
some[cp[i].id].r="C";
}
} sort(mp,mp+n,cmpm);
cal=;
if(some[mp[].id].rank>cal){
some[mp[].id].rank=cal;
some[mp[].id].r="M";
}
for(i=;i<n;i++){
if(mp[i].grade!=mp[i-].grade){
cal=i+;
}
if(some[mp[i].id].rank>cal){
some[mp[i].id].rank=cal;
some[mp[i].id].r="M";
}
} sort(ep,ep+n,cmpe);
cal=;
if(some[ep[].id].rank>cal){
some[ep[].id].rank=cal;
some[ep[].id].r="E";
}
for(i=;i<n;i++){
if(ep[i].grade!=ep[i-].grade){
cal=i+;
}
if(some[ep[i].id].rank>cal){
some[ep[i].id].rank=cal;
some[ep[i].id].r="E";
}
} map<string,somenode>::iterator it;
for(i=;i<m;i++){
cin>>num;
it=some.find(num);
if(it==some.end()){
cout<<"N/A"<<endl;
}
else{
cout<<some[num].rank<<" "<<some[num].r<<endl;
}
} delete []ap;
delete []cp;
delete []mp;
delete []ep;
return ;
}

pat1012. The Best Rank (25)的更多相关文章

  1. PAT-1012 The Best Rank (25 分) 查询分数对应排名(包括并列)

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  2. PAT1012:The Best Rank

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  3. 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 ...

  4. A1012 The Best Rank (25)(25 分)

    A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...

  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 ...

  6. 1012. The Best Rank (25)

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  7. The Best Rank (25)(排名算法)

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  8. 【PAT】1012. The Best Rank (25)

    题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...

  9. 1012 The Best Rank (25)(25 point(s))

    problem To evaluate the performance of our first year CS majored students, we consider their grades ...

随机推荐

  1. C#LIQN基础知识

  2. arp欺骗进行流量截获-1

    这边博文主要讲一下怎么使用arp欺骗进行流量截获,主要用于已经攻入内网以后,进行流量监听以及修改. 一.什么是arp     arp协议是以太网的基础工作协议,其主要作用是是一种将IP地址转化成物理地 ...

  3. SKU:唯一标识填什么

    策略 随意填写 只要别和别人重复就好 ,不过重复你也创建不了. 最好填与APP信息相关的,比如直接填写bundle ID 上去...跟套装ID保持一致. 你新建应用的时候都还没有APP ID 你怎么填 ...

  4. vmware实现物理机和虚拟机复制粘贴

    要实现物理机和虚拟机的复制粘贴需要安装VMware Tools. 1.点击菜单栏--虚拟机--安装VMware Tools. 2.打开linux终端,进入/media/VMware Tools目录. ...

  5. 51 nod 1267 4个数和为0

    1267 4个数和为0 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  取消关注 给出N个整数,你来判断一下是否能够选出4个数,他们的和为0,可以则输出& ...

  6. 【转】plsql 永久注册码适用个版本

    源地址:https://blog.csdn.net/sinat_33142609/article/details/72540025 注册码:Product Code:4t46t6vydkvsxekkv ...

  7. ObjectARX对话框添加颜色下拉组合框

    建立Arx基本对话框,最好是基于CAcUidialog类. 首先添加combox控件更改一下属性: 先修改Owner Draw为Fixed,再更改Has Strings 为true Has Strin ...

  8. centos 在vm下网络不通

    VMware是一款虚拟机,支持各种热门系统,我们可以在VMware虚拟机中安装其他系统以满足个人需求,但在为VMware安装CentOS6.5后,无法连接网络,这是什么原因导致的呢?下面就给大家介绍下 ...

  9. java 读取excel 2007 .xlsx文件 poi实现

    工作需要读取excel里面的行内容,使用java实现较为简单. 在最开始,尝试使用 jxl-2.6.12 来实现读取excel 的行内容.但是按照网上的方法,程序根本无法正确处理文件流.经过谷姐的一番 ...

  10. javaweb面试一

    1.forward与redirect区别,说一下你知道的状态码,redirect的状态码是多少? 状态码 说明 200 客户端请求成功 302 请求重定向,也是临时跳转,跳转的地址通过Location ...