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

完了,英文不好会死人呀,看了别人的解释才知道,是找出每个学生在A,C,M,E中的最好排名
如果在A、C、M、E排序过程中遇到同样的分数,需要有相同的排名,
比如在A这一科上5个人的成绩分别是100,90,90,88,87的话,排名应该是1,2,2,4,5,
这一点需要格外留意,不然没有办法通过所有测试。

 #include <iostream>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std; struct Data
{
string No;
int num;
int rank;
}; int main()
{
int N, M;
cin >> N >> M;
vector<Data>nums[];//A C M E
unordered_map <string, int>name;//用于学号查找
for (int i = ; i < N; ++i)
{
string No;
int c, m, e;
cin >> No >> c >> m >> e;
name[No]++;
nums[].push_back({ No,(c + m + e) / , });
nums[].push_back({ No,c, });
nums[].push_back({ No,m, });
nums[].push_back({ No,e, });
}
for (int i = ; i < ; ++i)
{
sort(nums[i].begin(), nums[i].end(), [](Data d1, Data d2) {return d1.num > d2.num; });
for (int j = ; j < nums[i].size(); ++j)
{
if (nums[i][j].num == nums[i][j - ].num)//处理相同分数
nums[i][j].rank = nums[i][j - ].rank;
else
nums[i][j].rank = j + ;//要跳过相同排名
}
} for (int j = ; j < M; ++j)
{
string No;
cin >> No;
int a, c, m, e;
if (name[No] == )
cout << "N/A" << endl;
else
{
for (int i = ; i < name.size(); ++i)
{
if (nums[][i].No == No) a = nums[][i].rank;
if (nums[][i].No == No) c = nums[][i].rank;
if (nums[][i].No == No) m = nums[][i].rank;
if (nums[][i].No == No) e = nums[][i].rank;
}
if (a <= c && a <= m && a <= e) cout << a << " " << "A" << endl;
else if (c <= a && c <= m && c <= e) cout << c << " " << "C" << endl;
else if (m <= a && m <= c && m <= e) cout << m << " " << "M" << endl;
else cout << e << " " << "E" << endl;
}
}
return ;
}

PAT甲级——A1012 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

    https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480 To evaluate the perfor ...

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

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

  4. PAT甲级——1012 The Best Rank

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

  5. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  6. A1012 The Best Rank (25)(25 分)

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

  7. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

  8. PAT甲级题分类汇编——排序

    本文为PAT甲级分类汇编系列文章. 排序题,就是以排序算法为主的题.纯排序,用 std::sort 就能解决的那种,20分都算不上,只能放在乙级,甲级的排序题要么是排序的规则复杂,要么是排完序还要做点 ...

  9. PAT甲级1056Mice and Rice

    目录 题目介绍 题解 解题思路 代码 参考链接 题目介绍 题目链接 https://pintia.cn/problem-sets/994805342720868352/problems/9948054 ...

随机推荐

  1. js单线程

    由于js是运行在单线程上的,所有浏览器单独开启一个线程来处理事件消息的轮询,避免阻塞js的执行.

  2. SpringCloud学习笔记(九):SpringCloud Config 分布式配置中心

    概述 分布式系统面临的-配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的服务.由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动 ...

  3. Docker系列(九):Kubernetes架构深度解析

    Kubernetes重要概念 Docker解决了打包和隔离的问题,但我们需要更多:调度的问题,生命周期及健康状况,服务发现,监控,认证,容器聚合. Kubernetes概述 开源DOcker容器编排系 ...

  4. AtCoder ABC 130E Common Subsequence

    题目链接:https://atcoder.jp/contests/abc130/tasks/abc130_e 题目大意 给定一个长度为 N 的序列 S 和一个长度为 M 的序列 T,问 S 和 T 中 ...

  5. Python3中面向对象 OOP

    Python3中面向对象 OOP 定义: python中通过关键字 class 实现类的定义: class ClassName(object): pass 获取成员变量:ClassName.变量名 修 ...

  6. East Central North America 2006 Hie with the Pie /// 状压dp oj22470

    题目大意: 输入n,有n个地方(1~n)需要送pizza pizza点为0点 接下来n+1行每行n+1个值 表示 i 到 j 的路径长度 输出从0点到各点送pizza最后回到0点的最短路(点可重复走) ...

  7. keepalived的常见的健康检查方式

    TCP_CHECK tcp端口检测 HTTP_GET http接口检测 MISC_CHECK 自定义脚本检测 tcp端口检测 TCP_CHECK { connect_port 80 connect_t ...

  8. adb 使用记录

    127.0.0.1:21503 adb kill -server adb start -server adb devices adb logcat | fing "cocos" a ...

  9. python Mean Squared Error vs. Structural Similarity Measure两种算法的图片比较

    # by movie on 2019/12/18 import matplotlib.pyplot as plt import numpy as np from skimage import meas ...

  10. leetcode 132 Palindrome Pairs 2

    lc132 Palindrome Pairs 2 大致与lc131相同,这里要求的是最小分割方案 同样可以分割成子问题 dp[i][j]还是表示s(i~j)是否为palindrome res[i]则用 ...