pat1012. The Best Rank (25)
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
注意点:
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)的更多相关文章
- PAT-1012 The Best Rank (25 分) 查询分数对应排名(包括并列)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT1012:The Best Rank
1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 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 ...
- A1012 The Best Rank (25)(25 分)
A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- 1012 The Best Rank (25分) vector与结构体排序
1012 The Best Rank (25分) To evaluate the performance of our first year CS majored students, we con ...
- 1012. The Best Rank (25)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- The Best Rank (25)(排名算法)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- 【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 ...
随机推荐
- Jenkins 自动化部署asp.net
使用步骤 1.安装jenkins.git和vs,并确保机器上安装了.net framework 4.5和.net framework4.0 ,完成后访问http://localhost:8080. 2 ...
- ecliplse集成SVN
按照下图操作 : SVN不同版本下载链接在文章底部有提供 上图点击add之后稍等一会就会弹出下图: 上图点击next之后: 最后等待完成之后重启ecliplse即可 重启ecliplse之后显示SVN ...
- loj#6437. 「PKUSC2018」PKUSC(计算几何)
题面 传送门 题解 计算几何的东西我好像都已经忘光了-- 首先我们可以把原问题转化为另一个等价的问题:对于每一个敌人,我们以原点为圆心,画一个经过该点的圆,把这个圆在多边形内部的圆弧的度数加入答案.求 ...
- spark-2.2.1在centos7安装
前言 在安装Spark之前,我们需要安装Scala语言的支持.在此我选择的是scala-2.11.12版本.jdk8也要保证已经安装好并且配置好环境变量 scala-2.11.12下载 为了方便,我先 ...
- flink学习笔记-数据源(DataSource)
说明:本文为<Flink大数据项目实战>学习笔记,想通过视频系统学习Flink这个最火爆的大数据计算框架的同学,推荐学习课程: Flink大数据项目实战:http://t.cn/EJtKh ...
- luogu3703 [SDOI2017]树点涂色(线段树+树链剖分+动态树)
link 你谷的第一篇题解没用写LCT,然后没观察懂,但是自己YY了一种不用LCT的做法 我们考虑对于每个点,维护一个fa,代表以1为根时候这个点的父亲 再维护一个bel,由于一个颜色相同的段一定是一 ...
- 如何把win10系统迁移到SSD固态硬盘
https://jingyan.baidu.com/article/5d368d1ec59ac43f60c05733.html 我之前将两个盘都已经固定在笔记本内,迁移完之后无论怎么改还是从原来的机械 ...
- 【转】LAMBDAFICATOR: Crossing the gap from imperative to functional programming through refactorings
Link:http://refactoring.info/tools/LambdaFicator/ Problem Description Java 8 will support lambda exp ...
- Python web前端 07 函数及作用域
Python web前端 07 函数及作用域 一.函数 1.有名函数和匿名函数 #函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块 #函数就是包裹在花括号里面的代码块,前面使用了关键字fun ...
- P4294 [WC2008]游览计划
传送门 斯坦纳树 给一个联通图,求 $k$ 个关键点联通的最小生成树权值 设 $f[o][i]$ 表示当前关键点选择状态为 $o$ ,以点 $i$ 为根的树的最小权值 初始 $f[1<<( ...