http://pat.zju.edu.cn/contests/pat-practise/1012
来源:互联网 发布:js中绑定含参数函数 编辑:程序博客网 时间:2024/04/30 12:13
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 A310101 98 85 88 90310102 70 95 88 84310103 82 87 94 88310104 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 Input5 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999Sample Output
1 C1 M1 E1 A3 AN/A
- #include<iostream>
- #include<cstdio>
- #include<memory.h>
- #include<algorithm>
- #include<cstring>
- #include<queue>
- #include<cmath>
- #include<cstdlib>
- #include<iomanip>
- #include<string>
- using namespace std;
- int way;
- int n;
- char cs[] = {'A', 'C', 'M', 'E'};
- struct Node{
- char id[8];
- int c, m, e;
- double a;
- int th;
- int myway;
- bool operator<(const Node& node)const{
- switch(way){
- case 1:return a>node.a;
- case 2:return c>node.c;
- case 3:return m>node.m;
- case 4:return e>node.e;
- }
- }
- };
- double getvalue(const Node & node){
- switch(way){
- case 1:return node.a;
- case 2:return node.c;
- case 3:return node.m;
- case 4:return node.e;
- }
- }
- Node nodes[3001];
- void print(char* id){
- for(int i=0;i<n;++i){
- if(!strcmp(id, nodes[i].id)){
- printf("%d %c\n", nodes[i].th, cs[nodes[i].myway-1]);
- return ;
- }
- }
- printf("N/A\n");
- }
- int main(){
- //freopen("in.txt", "r", stdin);
- int m;
- char id[8];
- while(cin>>n>>m){
- for(int i=0;i<n;++i){
- scanf(" %s %d %d %d", &nodes[i].id, &nodes[i].c, &nodes[i].m, &nodes[i].e);
- nodes[i].a = (nodes[i].c+nodes[i].e+nodes[i].m)/3;
- nodes[i].th = n+3;
- }
- way = 1;
- sort(nodes, nodes+n);
- nodes[0].th = 1;
- nodes[0].myway = 1;
- int pre = 1;
- for(int i=1;i<n;++i){
- int th;
- if(getvalue(nodes[i])==getvalue(nodes[i-1])){
- th = pre;
- }else{
- th = i+1;
- pre = th;
- }
- if(nodes[i].th>th){
- nodes[i].th = th;
- nodes[i].myway = 1;
- }
- }
- for(way=2;way<=4;++way){
- sort(nodes, nodes+n);
- if(nodes[0].th!=1){
- nodes[0].th = 1;
- nodes[0].myway = way;
- }
- pre = 1;
- for(int i=1;i<n;++i){
- int th;
- if(getvalue(nodes[i])==getvalue(nodes[i-1])){
- th = pre;
- }else{
- th = i+1;
- pre = th;
- }
- if(nodes[i].th>th){
- nodes[i].th = th;
- nodes[i].myway = way;
- }
- }
- }
- for(int i=0;i<m;++i){
- scanf(" %s", id);
- print(id);
- }
- }
- //fclose(stdin);
- return 0;
- }
- http://pat.zju.edu.cn/contests/pat-practise/1012
- http://pat.zju.edu.cn/contests/pat-practise/1012
- http://pat.zju.edu.cn/contests/pat-practise/1030
- http://pat.zju.edu.cn/contests/pat-practise/1034
- http://pat.zju.edu.cn/contests/pat-practise/1016
- http://pat.zju.edu.cn/contests/pat-practise/1032
- http://pat.zju.edu.cn/contests/pat-practise/1037
- http://pat.zju.edu.cn/contests/pat-practise/1021
- http://pat.zju.edu.cn/contests/pat-practise/1040
- http://pat.zju.edu.cn/contests/pat-practise/1038
- http://pat.zju.edu.cn/contests/pat-practise/1025
- http://pat.zju.edu.cn/contests/pat-practise/1023
- http://pat.zju.edu.cn/contests/pat-practise/1029
- http://pat.zju.edu.cn/contests/pat-practise/1035
- http://pat.zju.edu.cn/contests/pat-practise/1024
- http://pat.zju.edu.cn/contests/pat-practise/1031
- http://pat.zju.edu.cn/contests/pat-practise/1028
- http://pat.zju.edu.cn/contests/pat-practise/1020
- 关于java数据结构 在什么情况下使用什么样的数据结构的总结
- 越吃越胖的食物
- http://pat.zju.edu.cn/contests/pat-practise/1013
- 人民日报反驳我国地图曾承认钓鱼岛属日本说法-野田-钓鱼岛-国有化
- 调用网上在线聊天
- http://pat.zju.edu.cn/contests/pat-practise/1012
- Tizen简介
- 职场真言——让你变得更加“专业”
- CLI/C++中混合类的使用
- 网络分析笔记
- 分享浏览的文章、图片等信息到个人空间、微博……
- 国家公务员考试首次点名要大学生村官-国考-大学生-村官
- OC和ios中常用的一些类——Foundation框架的小结(1)
- 判断两个线段\矩形相交