PAT 甲级 1012 The Best Rank
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 C, M, E 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 C, M 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的更多相关文章
- PAT甲级1012. The Best Rank
PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- PAT甲级——1012 The Best Rank
PATA1012 The Best Rank To evaluate the performance of our first year CS majored students, we conside ...
- PAT——甲级1012:The Best Rank(有坑)
1012 The Best Rank (25 point(s)) To evaluate the performance of our first year CS majored students, ...
- 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 ...
- pat甲级1012
1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- 【PAT】1012. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
- PAT甲级——A1012 The Best Rank
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT甲级1012题解——选择一种合适数据存储方式能使题目变得更简单
题目分析: 本题的算法并不复杂,主要是要搞清楚数据的存储方式(选择一种合适的方式存储每个学生的四个成绩很重要)这里由于N的范围为10^6,故选择结构体来存放对应下标为学生的id(N只有2000的范围, ...
随机推荐
- Window10 Electron 开发环境搭建及打包exe程序
1.安装 Electron 首先要安装Node.js (安装方法:https://www.cnblogs.com/inkwhite/p/9685520.html) 我这里已经安装好了. 2:安 ...
- day 13 内置函数
内置函数思维导图:https://www.processon.com/view/link/5c13ad2de4b0ed122da75668 内置函数 作用域相关: locals() 返回当前作用域 ...
- Hadoop-Hive学习笔记(2)
1.Hive基本操作 #创建数据库hive>create database name;#创建新表hive> create table students(id int,name string ...
- Hadoop-Hive学习笔记(1)
1. Hive什么 a.Hive是基于Hadoop的一个数据仓库工具(注意不是数据仓库),将结构化的数据文件映射成一张数据库表. b.Hive是SQL的解析引擎,可以把sql语句转换成MapReduc ...
- 【NXP开发板应用—智能插排】1.如何使用scp传输文件
首先感谢深圳市米尔科技有限公司举办的这次活动并予以本人参加这次活动的机会,以往接触过嵌入式,但那都是皮毛,最多刷个系统之类的,可以说对于嵌入式系统开发这件事情是相当非常陌生的,这次活动为我提供了一个非 ...
- c语言杨氏矩阵算法
杨氏矩阵 有一个二维数组.数组的每行从左到右是递增的,每列从上到下是递增的.在这样的数组中查找一个数字是否存在.时间复杂度小于O(N);数组:1 2 32 3 43 4 5 1 3 42 4 54 5 ...
- 链表--数据结构与算法JavaScript描述(6)
链表 概念 链表是由一组节点组成的集合. 每个节点都使用一个对象的引用指向它的后继. 指向另一个节点的引用叫做 链. 许多链表的实现都在链表最前面有一个特殊节点,叫做头节点. 链表的尾元素指向一个nu ...
- 20145202马超《网络对抗》Exp5MSF基础应用
20145202马超<网络对抗>Exp5MSF基础应用 本实践目标,掌握metasploit的基本应用方式,掌握常用的三种攻击方式的思路.具体需要完成(1)一个主动攻击,如ms08_067 ...
- 关于 logger
日志 前言 我是一名后台程序员,接触后台只有一年时间,在这期间一共做过四个项目,分别是: 工作室招新系统 视频学习网站 创客网站 打印机项目 由于之前做项目的时候没有好好重视日志,所以导致在开发与维护 ...
- LeetCode: 62. Unique Paths(Medium)
1. 原题链接 https://leetcode.com/problems/unique-paths/description/ 2. 题目要求 给定一个m*n的棋盘,从左上角的格子开始移动,每次只能向 ...