题干:

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 CME 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 Specification:

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 CM and E. Then there are M lines, each containing a student ID.

Output Specification:

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

题目大意:

有n个学生,每个学生都有一个编号,和C,M,E三科的成绩,和三科的平均平均成绩A。为了鼓励学生,每一次询问给出一个学生编号,要求你输出这个学生的最高排名的科目和对应的排名。

解题报告:

因为这个题没说对于平均分的舍入处理,所以这题保存成double或者四舍五入都可以AC。

注意对于排名,可能有并列的情况。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e4 + 5;
struct Node {char name[12];int c,m,e,aa,cc,mm,ee;double a;int id;
} R[MAX];
bool cmp1(Node a,Node b) {return a.a > b.a;
}
bool cmp2(Node a,Node b) {return a.c > b.c;
}
bool cmp3(Node a,Node b) {return a.m > b.m;
}
bool cmp4(Node a,Node b) {return a.e > b.e;
}
bool cmp(Node a,Node b) {return a.id < b.id;
}
char name[MAX];
map<string,PII> mp;
char go(int x) {if(x == 1) return 'A';if(x == 2) return 'C';if(x == 3) return 'M';if(x == 4) return 'E';
}
int main()
{int n,m;cin>>n>>m;for(int i = 1; i<=n; i++) {scanf("%s%d%d%d",R[i].name,&R[i].c,&R[i].m,&R[i].e);R[i].a = (R[i].c + R[i].m + R[i].e) / 3.0; R[i].id = i;}sort(R+1,R+n+1,cmp1);int last = 0;for(int i = 1; i<=n; i++) {if(R[i].a == R[i-1].a) R[i].aa = last;else R[i].aa = i,last = i;}sort(R+1,R+n+1,cmp2); last = 0;for(int i = 1; i<=n; i++) {if(R[i].c == R[i-1].c) R[i].cc = last;else R[i].cc = i,last = i;}sort(R+1,R+n+1,cmp3); last = 0;for(int i = 1; i<=n; i++) {if(R[i].m == R[i-1].m) R[i].mm = last;else R[i].mm = i,last = i;}sort(R+1,R+n+1,cmp4); last = 0;for(int i = 1; i<=n; i++) {if(R[i].e == R[i-1].e) R[i].ee = last;else R[i].ee = i,last = i;}sort(R+1,R+n+1,cmp);for(int i = 1; i<=n; i++) {int item = 0,rk = 55555;if(R[i].aa < rk) item = 1,rk = R[i].aa;if(R[i].cc < rk) item = 2,rk = R[i].cc;if(R[i].mm < rk) item = 3,rk = R[i].mm;if(R[i].ee < rk) item = 4,rk = R[i].ee;mp[R[i].name] = pm(item,rk);}while(m--) {scanf("%s",name);if(mp.find(name) == mp.end()) printf("N/A\n");else printf("%d %c\n",mp[name].SS,go(mp[name].FF));}return 0 ;
}

【PAT - 甲级1012】The Best Rank (25分)相关推荐

  1. PAT 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) 今天给大家分享的是PAT甲级的一道小题,设计题 原题请点击我 简单翻译: 设计一个排名表,这个表中以学生ID为主键,C表示程序设计语言的成绩,M表示 ...

  2. PAT甲级1012 The Best Rank :[C++题解]4个成绩取排名最低:排序、二分(好题)

    文章目录 题目分析 题目链接 题目分析 遇到的问题:信息存在结构体(✖)中,然后排名呢?需要分别对 C.M.E.A排四次吗? 这里成绩的存储 用二维数组 vector<int> q[4]; ...

  3. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  4. PAT 甲级 1012 The Best Rank

    PAT 甲级 1012 The Best Rank To evaluate the performance of our first year CS majored students, we cons ...

  5. 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼

    题目 After each PAT, the PAT Center will announce the ranking of institutions based on their students' ...

  6. 【解析】1012 The Best Rank (25 分)

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 To evaluate the performance of our first year CS majored students ...

  7. PAT甲级 -- 1009 Product of Polynomials (25 分)

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  8. PAT甲级-1021 Deepest Root(25分)

    题目:1021 Deepest Root(25分) 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出 ...

  9. PAT甲级--1007 Maximum Subsequence Sum (25 分)

    题目详情 - 1007 Maximum Subsequence Sum (25 分) (pintia.cn) Given a sequence of K integers { N1​, N2​, .. ...

  10. 【PAT甲级 排序】1012 The Best Rank (25 分) C++ 全部AC

    题目 中规中矩的一道题.排名的顺序一开始没太明白,但是理解之后写起来挺流畅的,没什么坑. 解题思路:题目会给出所有学生所有科目的成绩.想要看分学生的学号. 我们要先给这些学生单科成绩排序,算出它们的单 ...

最新文章

  1. 读书笔记 - 《21世纪的管理挑战》
  2. PHP管理员登陆、验证与添加(前端验证)
  3. Python机器学习类库常见问题及解决
  4. JavaScript实现判断整数是否为2的幂isPowerOfTwo算法(附完整源码)
  5. ASP.NET:页面保存为WORD出现的问题!
  6. 进度条控制(Windows 公共进度栏控件的功能)
  7. 关于API和SDK的理解
  8. 知识图谱|各生命周期主流算法 实践
  9. Mac下安装graphviz以及XGBoost可视化决策树
  10. BZOJ4573[ZJOI2016] 大森林
  11. cardBattle游戏启动场景设计
  12. linux服务器校对时间方法
  13. oracle数据库中的回收站,Oracle回收站介绍
  14. opencv+ffmpeg+Qt h264录制
  15. 阿里云短信服务Java实现
  16. Wi-Fi PNO扫描流程(Android P)
  17. curl unmatched close brace/bracket 处理
  18. 招商银行信用卡还款冲账顺序
  19. 水逆的京东,2019还能翻盘吗?
  20. 网店新规的误读与媒体的谎言

热门文章

  1. HttpModules 管道过滤 自定义页面
  2. 使用SDL打造游戏世界之入门篇 - 7
  3. 语言差异引起的问题解决一例
  4. 新疆农业大学计算机科学与技术专业怎么样,新疆农业大学计算机科学与技术专业2016年在新疆理科高考录取最低分数线...
  5. mongodb如何根据字段(数组类型)的长度排序_大数据存储技术选型(七)——MongoDB设计模式及索引优化...
  6. python 访问sas 逻辑库,SAS | 逻辑库和SAS数据集
  7. vue v-if判断数组元素的值_Vue项目上线做的一些基本优化
  8. c语言字符串未初始化strcat,C语言中字符串常用函数strcat与strcpy的用法介绍
  9. idea maven创建java项目_新版本IntelliJ IDEA 构建maven,并用Maven创建一个web项目(图文教程)...
  10. 自梦php,PHP菜狗自学之路 云之梦php php之窗 php脚本之