1012 The Best Rank (25 point(s))

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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Student
{
char id[];
int A, C, M, E;//每个同学的分数
int A_rank, C_rank, M_rank, E_rank;//每个分数的排名
}stu[];
bool cmp_A(Student a, Student b) { return a.A > b.A; }//这四个函数是排序的时候用的,分别对四个成绩排序。
bool cmp_C(Student a, Student b) { return a.C > b.C; }
bool cmp_M(Student a, Student b) { return a.M > b.M; }
bool cmp_E(Student a, Student b) { return a.E > b.E; }
void print_max(int a, int c, int m, int e) {//这个函数打印出来最高排名。a c m e 分别代表的是各成绩排名。
if (a <= c && a <= m && a <= e)printf("%d A\n", a);//注意这里的=,符合优先级A>C>M>E
else if (c < a&&c <= m && c <= e)printf("%d C\n", c);
else if (m < a&&m < c && m <= e)printf("%d M\n", m);
else printf("%d E\n", e);
}
int main() {
int m, n;
scanf("%d%d", &n, &m);
for (int i = ;i < n;i++) {
scanf("%s%d%d%d", stu[i].id, &stu[i].C,&stu[i].M,&stu[i].E);
stu[i].A = (stu[i].C+stu[i].M + stu[i].E) / ;
} sort(stu, stu + n, cmp_A);//对A成绩排序
stu[].A_rank = ;
for (int i = ;i < n;i++) { //对A成绩排名
if (stu[i].A == stu[i - ].A)
stu[i].A_rank = stu[i - ].A_rank;
else
stu[i].A_rank = i + ;
}
//对C成绩排序,排名
sort(stu, stu + n, cmp_C);
stu[].C_rank = ;
for (int i = ;i < n;i++) {
if (stu[i].C == stu[i - ].C)
stu[i].C_rank = stu[i - ].C_rank;
else
stu[i].C_rank = i + ;
}
//对M成绩排序,排名
sort(stu, stu + n, cmp_M);
for (int i = ;i < n;i++) stu[i].M_rank = i + ;
stu[].M_rank = ;
for (int i = ;i < n;i++) {
if (stu[i].M == stu[i - ].M)
stu[i].M_rank = stu[i - ].M_rank;
else
stu[i].M_rank = i + ;
}
//对E成绩排序,排名
sort(stu, stu + n, cmp_E);
for (int i = ;i < n;i++) stu[i].E_rank = i + ;
stu[].E_rank = ;
for (int i = ;i < n;i++) {
if (stu[i].E == stu[i - ].E)
stu[i].E_rank = stu[i - ].E_rank;
else
stu[i].E_rank = i + ;
}
for (int i=;i < m;i++) {
char M_ID[];
bool flag = false;
scanf("%s", M_ID);
for (int j = ; j < n; j++)
{
if (strcmp(M_ID, stu[j].id) == ){//寻找这个同学的信息。
print_max(stu[j].A_rank, stu[j].C_rank, stu[j].M_rank, stu[j].E_rank);
flag = true;
break;
}
}
if (!flag) printf("N/A\n"); }
return ;
}

我这个可以改进一下,把id当int储存,题目中说了是6位数字。

并且后面处理查找ID的时候,复杂度比较高,算法笔记里面是申请了rank[10000000][4]这么大的数组。储存学生的排名信息,直接用ID去访问。但我总觉得申请这么大的内存,好虚呀,牺牲空间换时间。

其他我们的思路差不多。先储存,再分别排序,再对排序结果选择最高的输出。

这道题有个坑!

题目里面也没说,就是相同分数是怎么算排名。

比如91,90,88,88,84应该算作1,2,3,3,5。切记不要算作1,2,3,3,4。

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

    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甲 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. focal loss for dense object detection

    温故知新 focal loss for dense object detection,知乎上一人的评论很经典.hard negative sampling, 就是只挑出来男神(还是最难追的),而foc ...

  2. 课时91.CSS元素显示模式(掌握)

    在HTML中HTML将所有的标签分为两类,分别是容器级和文本级 在CSS中CSS也将所有的标签分为两类,分别是块级元素和行内元素 1.什么是块级元素,什么是行内元素? 块级元素会独占一行 行内元素不会 ...

  3. c# 分布式系统开发

    开篇吹牛,吹大牛了各位. 接连几篇博文,已经将了我们系统常用的东西,主要针对服务端,非桌面系统. 聊了这么久了,最后将这所有内容打包,完成一个系统.可能称为组件才合适,因为我没有提供启动程序. 每一个 ...

  4. JSP/Servlet开发——第六章 JSP开发业务应用

    1. 大容量的数据显示的缺点: ●当数据量较多时,用户需要拖动页面才能浏览更多信息: ●数据定位不便: 2.分页显示: ●既能显示多条数据,又不需要拖动页面,是数据更加清晰直观,页面不再冗长,也不受数 ...

  5. [NodeJs系列][译]理解NodeJs中的Event Loop、Timers以及process.nextTick()

    译者注: 为什么要翻译?其实在翻译这篇文章前,笔者有Google了一下中文翻译,看的不是很明白,所以才有自己翻译的打算,当然能力有限,文中或有错漏,欢迎指正. 文末会有几个小问题,大家不妨一起思考一下 ...

  6. springmvc请求数据的流程。

    验证了我说的,从model层中拿来的数据,不管什么类型,都是通过隐含模型,中转,放入request中的.除非你特意把这些数据放到session域中 流程含义解释:(来自网友)(1)HTTP请求到达we ...

  7. 【控制连接实现信息共享---linux和设备下ssh和远程连接telnet服务的简单搭建】

    SSH的配置 空密码登陆ssh server 如果要登录ssh server通常要在server和client之间采取具有共同加密的秘钥,若每次当client想要了:连接ssh server时都要手工 ...

  8. vue 数组数据更新或者对象数据更新 但是页面没有同步问题

    1,使用set函数来设置数据. 2,你可以通过 $forceUpdate 来做这件事.在数据赋值之后 就直接调用 this.$forceUpdata()

  9. zookeeper环境搭建(Linux)

    安装zookeeper 安装jdk(此处省略) 解压tar包并配置变量环境 配置文件修改 将/usr/local/src/zookeeper-3.4.5/conf这个路径下的zoo_sample.cf ...

  10. 002---Python基本数据类型--字符串

    字符串 .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1p ...