博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT_A 1012. The Best Rank (25)
阅读量:4226 次
发布时间:2019-05-26

本文共 4932 字,大约阅读时间需要 16 分钟。

1012. The Best Rank (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 Algebra), 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  A310101     98 85 88 90310102     70 95 88 84310103     82 87 94 88310104     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

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 C, M and E. Then there are M lines, each containing a student ID.

Output

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 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999
Sample Output
1 C1 M1 E1 A3 AN/A
应该用sort的..用qsort不仅麻烦还慢。
调用qsort把每个人的A C M E按照降序排列
注意若出现(90 90 81)的情况,则排名为(1 1 3)
#include 
#include
#include
#define MAX 2000#define DIG 7struct student { char id[DIG]; int c, m, e, a;};student record[MAX];struct C { char id[DIG]; int c;};struct M { char id[DIG]; int m;};struct E { char id[DIG]; int e;};struct A { char id[DIG]; int a;};A student_a[MAX];E student_e[MAX];M student_m[MAX];C student_c[MAX];int cmpA(const void *a, const void *b);int cmpC(const void *a, const void *b);int cmpM(const void *a, const void *b);int cmpE(const void *a, const void *b);int main() { int N, M; scanf("%d %d", &N, &M); for (int i = 0; i < N; i++) { scanf("%s %d %d %d", &record[i].id, &record[i].c, &record[i].m, &record[i].e); record[i].a = (int)((record[i].c + record[i].m + record[i].e) / 3.0 + 0.5); strcpy(student_a[i].id, record[i].id); strcpy(student_c[i].id, record[i].id); strcpy(student_e[i].id, record[i].id); strcpy(student_m[i].id, record[i].id); student_a[i].a = record[i].a; student_c[i].c = record[i].c; student_e[i].e = record[i].e; student_m[i].m = record[i].m; } qsort(student_c, N, sizeof(struct C), cmpC); qsort(student_m, N, sizeof(struct M), cmpM); qsort(student_e, N, sizeof(struct E), cmpE); qsort(student_a, N, sizeof(struct A), cmpA); for (int i = 0; i < M; i++) { char a[DIG]; bool flag = false; scanf("%s", &a); int rankC, rankM, rankE, rankA; for (int i = 0; i < N; i++) { if (strcmp(a, student_c[i].id) == 0) { flag = true; rankC = i + 1; for (int j = i - 1; j > -1; j--) { if (student_c[j].c == student_c[i].c) rankC--; else break; } break; } } if (flag == false) { printf("N/A\n"); } else { for (int i = 0; i < N; i++) { if (strcmp(a, student_m[i].id) == 0) { rankM = i + 1; for (int j = i - 1; j > -1; j--) { if (student_m[j].m == student_m[i].m) rankM--; else break; } break; } } for (int i = 0; i < N; i++) { if (strcmp(a, student_e[i].id) == 0) { rankE = i + 1; for (int j = i - 1; j > -1; j--) { if (student_e[j].e == student_e[i].e) rankE--; else break; } break; } } for (int i = 0; i < N; i++) { if (strcmp(a, student_a[i].id) == 0) { rankA = i + 1; for (int j = i - 1; j > -1; j--) { if (student_a[j].a == student_a[i].a) rankA--; else break; } break; } } if ((rankE < rankA) && (rankE < rankC) && (rankE < rankM)) { printf("%d E\n", rankE); } else if ((rankM < rankC) && (rankM < rankA)) { printf("%d M\n", rankM); } else if (rankC < rankA) { printf("%d C\n", rankC); } else { printf("%d A\n", rankA); } } } return 0;}int cmpA(const void *a, const void *b){ return (*(A*)b).a - (*(A*)a).a;}int cmpC(const void *a, const void *b){ return (*(C*)b).c - (*(C*)a).c;}int cmpM(const void *a, const void *b) { return (*(M*)b).m - (*(M*)a).m;}int cmpE(const void *a, const void *b){ return (*(E*)b).e - (*(E*)a).e;}

转载地址:http://etdqi.baihongyu.com/

你可能感兴趣的文章
一个好友的收藏。小洪(洪承煜),不打招呼就转载一下罗,呵呵
查看>>
面试必问的16个经典问题的回答思路
查看>>
丹阳买眼镜攻略1
查看>>
ubuntu安装与删除软件的命令
查看>>
单片机指令大全(精简)
查看>>
MCS-51单片机的指令时序
查看>>
51单片机总线时序
查看>>
USB学习
查看>>
C语言的lex和yacc工具说明
查看>>
C语言编译全过程
查看>>
数字集成资料
查看>>
使用U盘安装Ubuntu 9.10
查看>>
SmartARM2200启动文件分析
查看>>
关于ARM的三种中断调试方法介绍
查看>>
armlink使用方法详解
查看>>
armlink - Scatter file文件格式
查看>>
链接脚本文件是什么,怎样编写
查看>>
RO,RW和ZI的理解
查看>>
关于ARM汇编中字符串表达式及运算符总结
查看>>
试用ubuntu9.10体会 + grub2 +双linux系统
查看>>