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 (≤2000), 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 <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = ;
struct stu{
int id;
int grade[];
};
vector<stu> vs;
int myrank[maxn][];
char list[] = { 'A', 'C', 'M', 'E' };
int now;
bool cmp(stu s1, stu s2){
return s1.grade[now] > s2.grade[now];
}
int main(){
int n, m;
scanf("%d %d", &n, &m);
for (int i = ; i<n; i++){
int id;
int c, m, e, a;
scanf("%d", &id);
scanf("%d %d %d\n", &c, &m, &e);
stu s;
s.id = id;
s.grade[] = c;
s.grade[] = m;
s.grade[] = e;
a = c + m + e;
s.grade[] = a;
vs.push_back(s);
}
for (now = ; now < ; now++){
sort(vs.begin(), vs.end(), cmp);
myrank[vs[].id][now] = ;
for (int k = ; k < n; k++){
if (vs[k].grade[now] != vs[k - ].grade[now]){
myrank[vs[k].id][now] = k + ;
}
else{
myrank[vs[k].id][now] = myrank[vs[k-].id][now];
}
}
}
for (int i = ; i < m; i++){
int j;
scanf("%d", &j); if (myrank[j][] != ){
int best = maxn, best_k = ;;
for (int k = ; k < ; k++){
if (myrank[j][k]<best){
best_k = k;
best = myrank[j][k];
}
}
printf("%d %c\n", myrank[j][best_k], list[best_k]);
}
else{
printf("N/A\n");
}
}
}

注意点:很简单的一道题目,却花了一个多小时,一开始题目意思理解错了,虽然就算理解对了,也一样。就觉得很麻烦,要开好多个数组,加好多属性,总觉得可能有捷径,就一直不下手。反思一下,就是要用最笨的最麻烦的方法先写出来,如果超时了,再去想哪里可以改进。这道题就是直接开个记录排名的数组,或者在结构体里加上各个成绩的排名属性,每个都排一下序,记录下来。这里唯一的小技巧是记录成绩用一个数组,而不是4个int,这样写cmp函数只要写一个。

PAT A1012 The Best Rank (25 分)——多次排序,排名的更多相关文章

  1. PAT-1012 The Best Rank (25 分) 查询分数对应排名(包括并列)

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  2. PAT A1146 Topological Order (25 分)——拓扑排序,入度

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...

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

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

  4. 1012 The Best Rank (25分) vector与结构体排序

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

  5. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

    题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...

  6. PAT A1122 Hamiltonian Cycle (25 分)——图遍历

    The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...

  7. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  8. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  9. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  10. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

随机推荐

  1. Java基础——Ajax(二)

    一.jQuery 实现 ajax $(function(){ $("#userName").blur(function(){ // 发ajax请求 用的函数原型: $.get(ur ...

  2. 《深入理解Java虚拟机:JVM高级特性与最佳实践》读书笔记

    第一部分 走进Java 一.走进Java 1.概述 java广泛应用于嵌入式系统.移动终端.企业服务器.大型机等各种场合,摆脱了硬件平台的束缚,实现了“一次编写,到处运行”的理想 2.java技术体系 ...

  3. CSS如何让不相等的字符上下对齐

    最后效果: <div class="main"> <span style="font-size:12px;"><dl class= ...

  4. 测试思想 QA的价值体现

    QA的价值体现 by:授客 QQ:1033553122 1.  缺陷挖掘价值 QA人员一个很重要的价值就是在尽可能短的时间内找出尽可能多的缺陷. 某种意义上说,缺陷直观的反应了产品的质量,QA发现的有 ...

  5. Cordova/Ionic开发的Android APP启用Chrome Inspect调试的方法

    Cordova/Ionic开发的Android APP,需要启用WebView的调试模式,才可以在Chrome浏览器中输入chrome://Inspect,然后使用大家熟悉的开发者工具进行调试.不启用 ...

  6. git本地仓库关联多个remote,怎么用本地一个分支向不同remote不同分支推送代码

    我想这个问题,是大家关注的问题,这个问题,我非常关注. 背景:在公司开发项目,我们一般都要把项目推送到公司领导创建的一个远程仓库里边去,但是我们同时也有自己的小仓库,这样的话,如何方便的将我们的代码, ...

  7. flask中的url_for的使用

    有多个路由的程序需要连接不同的网页链接,例如导航条 模板中构建正确的动态url较为困难,如果重定义路由,模板中的链接失效 url_for()函数: 使用url映射中保存的信息生成url 用法: 用视图 ...

  8. [20180608]Wrong Results with IOT, Added Column and Secondary Index.txt

    [20180608]Wrong Results with IOT, Added Column and Secondary Index.txt --//链接:http://db-oriented.com ...

  9. Install Google Chrome on Fedora 28/27, CentOS/RHEL 7.5 (在 fedora 28 等 上 安装 chrome)

    今天在使用 fedora 安装 chrome 的时候遇到了问题,今天进行将安装过程进行记录下来.需要安装第三方软件仓库. 我们需要进行安装 fedora-workstation-repositorie ...

  10. windows 实用技巧

    以下内容版权归原作者所有!!!如果侵权,立即删除. 1.系统激活:https://mp.weixin.qq.com/s/Kl_iEeSSxSprblfSRZ6yEQ 2.百度云下载:https://w ...