https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480

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 (≤), 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

代码:

#include <bits/stdc++.h>
using namespace std; int n, m;
map<int, int> mp; struct Node{
int A, C, M, E;
int na, nc, nm, ne;
int id;
}node[2020]; bool cmpA(const Node& a, const Node& b) {
return a.A > b.A;
} bool cmpC(const Node& a, const Node& b) {
return a.C > b.C;
} bool cmpM(const Node& a, const Node& b) {
return a.M > b.M;
} bool cmpE(const Node& a, const Node& b) {
return a.E > b.E;
} void print(int idd) {
int a[8];
for(int i = 0; i < n; i ++)
if(node[i].id == idd) {
int temp = i;
a[0] = node[temp].na, a[1] = node[temp].nc, a[2] = node[temp].nm, a[3] = node[temp].ne;
sort(a, a + 4);
if(a[0] == node[temp].na)
printf("%d A\n", node[temp].na);
else if(a[0] == node[temp].nc)
printf("%d C\n", node[temp].nc);
else if(a[0] == node[temp].nm)
printf("%d M\n", node[temp].nm);
else
printf("%d E\n", node[temp].ne);
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i ++) {
scanf("%d%d%d%d", &node[i].id, &node[i].C, &node[i].M, &node[i].E);
node[i].A = (node[i].C + node[i].M + node[i].E) / 3;
mp[node[i].id] = 1;
}
sort(node, node + n, cmpA);
node[0].na = 1;
for(int i = 1; i < n; i ++) {
if(node[i].A == node[i - 1].A)
node[i].na = node[i - 1].na;
else node[i].na = i + 1;
}
sort(node, node + n, cmpC);
node[0].nc = 1;
for(int i = 1; i < n; i ++) {
if(node[i].C == node[i - 1].C)
node[i].nc = node[i - 1].nc;
else node[i].nc = i + 1;
}
sort(node, node + n, cmpM);
node[0].nm = 1;
for(int i = 1; i < n; i ++) {
if(node[i].M == node[i - 1].M)
node[i].nm = node[i - 1].nm;
else node[i].nm = i + 1;
}
sort(node, node + n, cmpE);
node[0].ne = 1;
for(int i = 1; i < n; i ++) {
if(node[i].E == node[i - 1].E)
node[i].ne = node[i - 1].ne;
else node[i].ne = i + 1;
}
while(m --) {
int x;
scanf("%d", &x);
if(!mp[x])
printf("N/A\n");
else
print(x);
}
return 0;
}

  几乎看了一个下午的搜索 头皮发麻 这个代码觉得写得好麻烦 恰饭去了

PAT 甲级 1012 The Best Rank的更多相关文章

  1. PAT甲级1012. The Best Rank

    PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...

  2. PAT 甲级 1012 The Best Rank (25 分)(结构体排序)

    题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...

  3. PAT甲级——1012 The Best Rank

    PATA1012 The Best Rank To evaluate the performance of our first year CS majored students, we conside ...

  4. PAT——甲级1012:The Best Rank(有坑)

    1012 The Best Rank (25 point(s)) To evaluate the performance of our first year CS majored students, ...

  5. 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 ...

  6. pat甲级1012

    1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...

  7. 【PAT】1012. The Best Rank (25)

    题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...

  8. PAT甲级——A1012 The Best Rank

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  9. PAT甲级1012题解——选择一种合适数据存储方式能使题目变得更简单

    题目分析: 本题的算法并不复杂,主要是要搞清楚数据的存储方式(选择一种合适的方式存储每个学生的四个成绩很重要)这里由于N的范围为10^6,故选择结构体来存放对应下标为学生的id(N只有2000的范围, ...

随机推荐

  1. reids同步机制和远程连接

    RDB同步机制: 开启和关闭:默认情况下是开启了.如果想关闭,那么注释掉redis.conf文件中的所有save选项就可以了. 同步机制: save 900 1:如果在900s以内发生了1次数据更新操 ...

  2. python3 urllib爬取wallhalla网站图片

    点我去我的github上看源码 简单使用静态方法爬取https://wallhalla.com/网站的图片 参考: https://blog.csdn.net/cquptcmj/article/det ...

  3. Java基础之final和abstract关键字

    final final在Java中是一个保留的关键字,可以声明成员变量.方法.类以及本地变量.一旦你将引用声明作final,你将不能改变这个引用了,编译器会检查代码,如果你试图将变量再次初始化的话,编 ...

  4. 实验1 查看CPU和内存,用机器指令和汇编指令编程

    ·实验任务 (1)使用Debug,用E命令和A命令以两种方式将指令写入内存 机器码        汇编指令 b8 20 4e    mov ax,4e20h 05 16 14    add ax,14 ...

  5. auto、static、extern

  6. [Oracle]关于Oracle分页写法的性能分析及ROWNUM说明

    关于分页写法的性能分析及ROWNUM的补充说明 分页写法 一.测试前数据准备 SQL> SELECT COUNT(*) FROM BPM_PROCVAR; COUNT(*) ---------- ...

  7. Linux getcwd()的实现

    通过getcwd()可以获取当前工作目录. #include <unistd.h> char *getcwd(char *cwdbuf, size_t size); 成功调用返回指向cwd ...

  8. iOS应用App Store发布流程

    iOS应用App Store发布流程 要发布iOS应用到App Store首先得有一个开发者账号,且不能是企业版(企业版只能部署inhouse,不能部署到App Store). 应用发布到App St ...

  9. 在VMware虚拟机下安装Linux CentOS7

    1.首先下载并安装VMware虚拟机,下载地址:https://www.vmware.com/cn/products/workstation-pro/workstation-pro-evaluatio ...

  10. php单例模式和工厂模式

    单例模式:防止重复实例化,避免大量的new操作,减少消耗系统和内存的资源,使得有且仅有一个实例对象 header("Content-type: text/html; charset=utf- ...