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. 尚学python课程---12、python语言介绍

    尚学python课程---12.python语言介绍 一.总结 一句话总结: 1.操作简单:简便计算:允许通过单个“import”语句后跟一个函数调用来完成复杂的计算.虽慢 2.库丰富:比如人工智能和 ...

  2. Linux课程---14、linux下lamp环境如何安装

    Linux课程---14.linux下lamp环境如何安装 一.总结 一句话总结: 要按顺序安装,比如apache需要在php之前安装, 一.安装 gcc 编译器 二.卸载 rpm 安装的 http ...

  3. Windows的哈希

    Windows中有几种不同类型的哈希值,它们可能非常混乱. 可以在这两篇文章<LM, NTLM, Net-NTLMv2, oh my!>和<LM Hash and NT Hash & ...

  4. DIV常用属性大全自己整理

    一.属性列表 代码如下: color : #999999 文字颜色 font-family : 宋体 文字字型 font-size : 10pt 文字大小 font-style:itelic 文字斜体 ...

  5. Hadoop 2.x 版本中的依赖 jar

  6. login-Linux必学的60个命令

    1.作用 login的作用是登录系统,它的使用权限是所有用户. 2.格式 login [name][-p ][-h 主机名称] 3.主要参数 -p:通知login保持现在的环境参数. -h:用来向远程 ...

  7. nodejs入门最简单例子

    一.mac话,先安装nodejs环境: brew install nodejs 二.先写一个main.js var http = require("http"); http.cre ...

  8. 常见的React面试题

    1.redux中间件 答:中间件提供第三方插件的模式,自定义拦截 action -> reducer 的过程.变为 action -> middlewares -> reducer ...

  9. layui相关用法总结

    1.关闭当前弹出层 parent.layer.close(parent.layer.getFrameIndex(window.name));

  10. 【JZOJ3236】矮人排队

    description 在七山七海之外的一个小村庄,白雪公主与N个矮人住在一起,所有时间都花在吃和玩League of Legend游戏.白雪公主决心终结这样的生活,所以为他们举办了体育课. 在每节课 ...