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. arcconf工具操作手册V1.0

    arcconf工具操作手册 1.1.1  arcconf工具初始化和去初始化硬盘 [命令功能] PMC阵列卡系统下初始化硬盘,可以将raw盘状态变成ready状态,以便进一步组建raid和设置热备盘: ...

  2. 定时器timer类

    timer类 Timer(定时器)是Thread的派生类,用于在指定时间后调用一个方法. 构造方法: Timer(interval, function, args=[], kwargs={})  in ...

  3. 多线程《四》Thread对象的其他属性和方法

    Thread对象的其他属性或方法 介绍 Thread实例对象的方法 # isAlive(): 返回线程是否活动的. # getName(): 返回线程名. # setName(): 设置线程名. th ...

  4. Python+selenium爬取智联招聘的职位信息

    整个爬虫是基于selenium和Python来运行的,运行需要的包 mysql,matplotlib,selenium 需要安装selenium火狐浏览器驱动,百度的搜寻. 整个爬虫是模块化组织的,不 ...

  5. 【bzoj1009】: [HNOI2008]GT考试 字符串-kmp-矩阵乘法-DP

    [bzoj1009]: [HNOI2008]GT考试 先用kmp写个暴力 /* http://www.cnblogs.com/karl07/ */ #include <cstdlib> # ...

  6. luoguP4782 [模板]2-SAT问题

    https://www.luogu.org/problemnew/show/P4782 2-SAT模板,输出方案只需判断 \(a\) 和 \(a + n\) 两个点所在的 scc 编号大小就可以了 # ...

  7. PHP编码技巧

    原则 正确实现功能 执行速度与快 占系统资源少 后期维护方便 编程注意 1.命名很重要 2.适当的使用注释 3.使用一个变量,需要初始化 4.优先使用单引号 $row['id']的效率是$row[id ...

  8. SDUT OJ 多项式求和

    多项式求和 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 多项式描述 ...

  9. CentOS7.4关闭防火墙

    //临时关闭 systemctl stop firewalld //禁止开机启动 systemctl disable firewalld Removed symlink /etc/systemd/sy ...

  10. Centos7.4 更换国内yum源

    1.进入yum源配置文件夹.(配置之前先看看有没有安装wget命令呢,没的话可以先用当前的yum源安装一下再说.yum -y install wget) 2.转到配置文件目录  cd /etc/yum ...