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. STM32_3 时钟初始化分析

    在startup文件中,调用了2个函数,一个是System_Init, 另一个是main. System_Init()在system_stm32f10x.c 这个文件中,先看一下时钟树,再分析一下这个 ...

  2. Shell--cut用法

    cut是以每一行为一个处理对象的,这种机制和sed一样. cut接受三个定位方法: 1)byte: -b 2)characters: -c 3)fields: -d eg:提取第3,4,5,9的字节: ...

  3. 菜鸟学Linux - 变量基本规则

    变量是一个很重要的概念,无论是bash脚本还是其他语言,都是如此.在bash中,创建变量很简单,给变量一个名称即可.默认情况下,变量的值为空.我们可以通过等号为变量赋值.需要注意的是,变量和变量的值不 ...

  4. 北京Uber优步司机奖励政策(4月4日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. 成都Uber优步司机奖励政策(3月9日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  6. underscore.js 分析 第二天

    Underscore源码中有这么句obj.length === +obj.length意思是typeof obj.length == number,即检测obj的长度是否是数字我的理解:这么写是来检测 ...

  7. 小组ITalk网站开发中使用到的一些技巧

    ----->Display属性和Visibility属性:一个清除内容和框体,另一个只清除内容而保留窗体: $('#abc').css({ 'font-size' : '12px', '-web ...

  8. lintcode12 带最小值操作的栈

    实现一个带有取最小值min方法的栈,min方法将返回当前栈中的最小值. 你实现的栈将支持push,pop 和 min 操作,所有操作要求都在O(1)时间内完成. 建一个栈helpStack,用来存放从 ...

  9. Java 消息对列

    ActiveMQ入门实例   1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.5. ...

  10. JAVA基础学习之路(三)类定义及构造方法

    类的定义及使用 一,类的定义 class Book {//定义一个类 int price;//定义一个属性 int num; public static int getMonney(int price ...