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. React的安装方法

    一:直接使用 BootCDN 的 React CDN 库,地址如下: <script src="https://cdn.bootcss.com/react/16.4.0/umd/rea ...

  2. Django学习之模拟架构页面跳转

    背景知识,需要有一定量的HTTP基础知识 在客户端游览器通过URL向服务端发送请求时,经历了两次过程.一次是URL向服务端发起请求,一次是服务端向客户端回发响应. 由图可知,客户端一共传递两个信息,一 ...

  3. 分享一个强大的makedown编辑器

    Yosoro 官网地址 https://yosoro.coolecho.net/ 很强大,支持直接粘贴图片,是直接上传到github仓库. 可直接导出md,html,pdf格式,特别方便 找了好几天的 ...

  4. Java设计模式(7)——结构型模式之适配器模式(Adapter)

    一.概述 概念 其实,举个生活中的例子的话,适配器模式可以类比转接头,比如typeC和USB的转接头,把原本只能接typeC的接口,拓展为可以接普通USB:这里的转接头一方面需要查在typeC上,一方 ...

  5. TensorFlow:在PyCharm中配置TensorFlow

    在本地配置好TensorFlow后,如何在PyCharm中配置TensorFlow呢? 只需将当前的Python编译环境配置为TensFlow安装路径中的Pyhton环境,具体操作如下: 1. 打开‘ ...

  6. 阅读笔记《JavaScript高级程序设计》

    0. 严格模式 "user strict" (1整个脚本顶部,2函数体顶部) 1. 数据类型 undefined -- 未定义 boolean string number obje ...

  7. L010 linux命令及基础手把手实战总结

    一转眼都快两周没更新了,最近实在太忙了,这两周的时间断断续续的把L010学完了,短短的15节课,确是把前10节的课程全部的运用一遍,从笔记到整理,再到重新理解,最后发布到微博,也确实提升了一些综合性能 ...

  8. 【转】Oracle 如何找回已经删除了的表记录

    有的时候我们不小心把数据库表(emp)中重要的记录给删除了,怎么给找回来了,看下面这个例子你就会明白. 某一天,10点钟的时候,张三一不小心给数据库表emp的一条重要记录给删除了并且还提交了,此时也没 ...

  9. Java基础知识总结一

    1.何为编程? 编程就是让计算机为解决某个问题而使用某种程序设计语言编写程序代码,并最终得到结果的过程. 为了使计算机能够理解人的意图,人类就必须要将需解决的问题的思路.方法.和手段通过计算机能够理解 ...

  10. photoshop cc 2018安装破解教程(破解补丁,亲测,绝对可用)

    破解步骤说明:下载地址百度网盘,https://pan.baidu.com/s/1cWtpUesl2fms3tFwEC0MiQ 1.右键解压Adobe Photoshop CC 2018 64位这个文 ...