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 ...
随机推荐
- C语言/C++编程学习三种循环用法和区别
C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...
- 871. Minimum Number of Refueling Stops
A car travels from a starting position to a destination which is target miles east of the starting p ...
- Jmeter_Beanshell_使用Java处理JSON块
版权声明:本文为博主原创文章,转载请注明出处. [环境] ①Jmeter版本:3.2,JDK:1.8 ②前置条件:将json.jar包置于..\apache-jmeter-3.2\lib\下,并将该j ...
- winform未能加载Interop.WMPLib
找到这个引用,然后移除既即可以
- springboot集成巨杉数据库
springboot倾向于约定优于配置,所以大大简化了搭建项目的流程,包括各种数据源的配置,接下来就和大家分享下最近用到的巨杉数据源连接池的配置 1.现在配置文件中定义巨杉连接池的各种连接信息,至于每 ...
- 传智播客Springmvc_mybatis学习笔记
文件地址:https://download.csdn.net/download/qq_26078953/10614459
- Preprefix sum BZOJ 3155 树状数组
题目描述 前缀和(prefix sum)Si=∑k=1iaiS_i=\sum_{k=1}^i a_iSi=∑k=1iai. 前前缀和(preprefix sum) 则把SiS_iSi作为原序列 ...
- centos 安装搜狗
原文:https://www.cnblogs.com/blueherb/p/9521827.html 1.通过centos的搜狐到百度下载linux fo sougou 注:找到下载路径(定义为A) ...
- 用IDM下载博客图片
前言 写博客的人一定都会有一个图床,将图片存在那里.发现自己以前没有注意图片来源问题,随手就贴在博客上面了.现在有不少图片都挂了,换句话来说有可能自己目前用的图床不提供服务了,那所有的图片都有可能丢失 ...
- javascrip 词法分析详解
JavaScript的高级知识---词法分析 词法分析 词法分析方法: js运行前有一个类似编译的过程即词法分析,词法分析主要有三个步骤: 分析参数 再分析变量的声明 分析函数说明 函数在运行的瞬 ...