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 ...
随机推荐
- Server Sql 多表查询、子查询和分页
一.多表查询:根据特定的连接条件从不同的表中获取所需的数据 多表查询语法: SELECT table1.column, table2.column FROM table1, table2 WHERE ...
- javascript webstorm用法
javascript webstorm用法 一.什么是webstorm? WebStorm 是jetbrains公司旗下一款JavaScript 开发工具.被广大中国JS开发者誉为“We ...
- JavaScript 如何工作:渲染引擎和性能优化技巧
翻译自:How JavaScript works: the rendering engine and tips to optimize its performance 这是探索 JavaScript ...
- 「CF 600E」 Lomsat gelral
题目链接 戳我 \(Describe\) 给出一棵树,每个节点有一个颜色,求每个节点的子树中颜色数目最多的颜色的和. \(Solution\) 这道题为什么好多人都写的是启发式合并,表示我不会啊. 这 ...
- 题解 P1436 【棋盘分割】
题目链接 其实呢大致思路和下面的大佬们都很像.发这篇题解的目的就是加了一点~~优化~~骗分技巧. 转移方程: 设$dp[i][j][x][y][k]$表示左上$(i,j)$,右下$(x,y)$,第$k ...
- luoguP4782 [模板]2-SAT问题
https://www.luogu.org/problemnew/show/P4782 2-SAT模板,输出方案只需判断 \(a\) 和 \(a + n\) 两个点所在的 scc 编号大小就可以了 # ...
- go语言排序
冒泡: package main import ( "fmt" ) func BubbleSort(arr []int) []int { // 改进的冒泡排序 num := len ...
- Servlet的概念与用法
Servlet: Servlet(Servlet+Applet) Servlet是一种独立于平台和协议的服务器端Java应用程序,通用Servlet 可以生成动态Web页面.Servlet还 ...
- 数组常用的API——splice()截取
他的几个作用:截取 删除 增加 替换. 当传递一个参数的时候 : 截取开始的位置,参数代表下标,默人会截取到结束的位置. 当传递两个参数的时候: 第一个参数是删除的下标: 第二个参数代表删除几个 ...
- 启动Tomcat报错
如果发现引入jar包有问题时,看jar包是否损坏,变成了0kb.如果是这样,在网上试尽解决办法也是有问题的. 一般Tomcat启动报错,要引入这两个jar包.