浙大pat 1012题解
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 Algrbra), 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
#include"iostream"
#include "algorithm"
#include <map>
#include <iomanip>
#include"string.h"
#include "vector"
using namespace std;
struct Student
{
int id;
int C;
int M;
int E;
int A;
};
bool compareA(Student a,Student b)
{
return a.A>b.A;
}
bool compareC(Student a,Student b)
{
return a.C>b.C;
}
bool compareM(Student a,Student b)
{
return a.M>b.M;
}
bool compareE(Student a,Student b)
{
return a.E>b.E;
}
int main()
{
vector<Student> stus;
map<int,char> Type;
map<int,int> Rank;
Student s;
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&s.id,&s.C,&s.M,&s.E);
s.A=(s.C+s.M+s.E)/3;
stus.push_back(s);
}
int score = -1;
int rank =0;
sort(stus.begin(),stus.end(),compareA);
for(int i=0;i<stus.size();i++)
{
if(stus[i].A!=score)
{
rank = i+1;
}
score = stus[i].A;
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'A';
}
score = -1;
rank =0;
sort(stus.begin(),stus.end(),compareC);
for(int i=0;i<stus.size();i++)
{
if(stus[i].C!=score)
{
rank = i+1;
}
score = stus[i].C;
if(Rank[stus[i].id]>rank)
{
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'C';
}
}
score = -1;
rank =0;
sort(stus.begin(),stus.end(),compareM);
for(int i=0;i<stus.size();i++)
{
if(stus[i].M!=score)
{
rank = i+1;
}
score = stus[i].M;
if(Rank[stus[i].id]>rank)
{
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'M';
}
}
score = -1;
rank =0;
sort(stus.begin(),stus.end(),compareE);
for(int i=0;i<stus.size();i++)
{
if(stus[i].E!=score)
{
rank = i+1;
}
score = stus[i].E;
if(Rank[stus[i].id]>rank)
{
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'E';
}
}
int Q;
for(int i=0;i<m;i++)
{
cin>>Q;
if(Type.count(Q))
cout<<Rank[Q]<<" "<<Type[Q]<<endl;
else
cout<<"N/A"<<endl;
}
return 0;
}
浙大pat 1012题解的更多相关文章
- 浙大pat 1035题解
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...
- 浙大pat 1025题解
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大PAT 7-06 题解
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 浙大 pat 1038 题解
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- 浙大pat 1054 题解
1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...
- 浙大pat 1059 题解
1059. Prime Factors (25) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...
随机推荐
- IE6的那些css常见bug(汇总)
IE6的那些css常见bug(汇总) 我的微博终于在前几天建立了 虽说很早之前就知道博客园这个地方 但怕自己不能坚持去写一些东西一直没有建.这几天 我做了这个决定 把我的博客建起来 每周发一些看到的, ...
- springMVC3学习(四)--访问静态文件如js,jpg,css
如果你的DispatcherServlet拦截的是*.do这样的URL,就不存在访问不到静态资源的问题 如果你的DispatcherServlet拦截了"/"所有的请求,那同时对* ...
- IceMx.Mvc 我的js MVC 框架六、完善植物大战僵尸(向日葵登场)
有图有真相,废话不多说上图 看到园友的支持很受鼓舞,更觉得应该做下去,虽然自己是个菜鸟,但也应该共享自己的心得,只要有人获益那就是值得的. 我的下载需要csdn论坛的1个积分,之所以不完全免费出去是因 ...
- JS自动刷新页面一次
<script type="text/javascript"> //刷新页面 if(location.href.indexOf("refresh=1" ...
- WCF 学习笔记之异常处理
WCF 学习笔记之异常处理 1:WCF异常在配置文件 <configuration> <system.serviceModel> <behaviors> <s ...
- enode框架step by step之框架的物理部署思路
enode框架step by step之框架的物理部署思路 enode框架系列step by step文章系列索引: enode框架step by step之开篇 enode框架step by s ...
- cooking eggs
1: what is egg? what's the shape of it in details? 2: can egg run like this http://item.taobao.com/i ...
- web系统数据导出功能设计实现(导出excel2003/2007 word pdf zip等)
web系统数据导出功能设计实现(导出excel2003/2007 word pdf zip等) 前言 我们在做web系统中,导出也是很常用的一个功能,如果每一个数据列表都要对应写一个导出的方法不太现实 ...
- 死锁线程探讨Java中的死锁现象
题记:写这篇博客要主是加深自己对死锁线程的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 今天搞了一下Java的死锁机制,感到自己还是不怎么懂,所以就从一些简略的源代码中琢磨:我先 ...
- Android屏幕适配问题详解
上篇-Android本地化资源目录详解 :http://www.cnblogs.com/steffen/p/3833048.html 单位: px(像素):屏幕上的点. in(英寸):长度单位. mm ...