PAT_A 1012. The Best Rank (25)

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  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

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 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
应该用sort的..用qsort不仅麻烦还慢。
调用qsort把每个人的A C M E按照降序排列
注意若出现(90 90 81)的情况,则排名为(1 1 3)
#include <stdio.h>
#include <string.h>
#include <algorithm>

#define MAX 2000
#define DIG 7

struct 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;
}


select distinct a.EMPI_ID, a.PATIENT_NO, a.MR_NO, a.PAT_NAME, a.PAT_SEX, a.PAT_AGE, a.PAT_PHONE_NO, b.DIAG_RESULT, a.ADMIT_DATE, a.DISCHARGE_DEPT_NAME, a.ATTEND_DR from BASIC_INFORMATION a join PA_DIAG b on a.MZZY_SERIES_NO=b.MZZY_SERIES_NO join EXAM_DESC_RESULT_CODE c on a.MZZY_SERIES_NO=c.MZZY_SERIES_NO join DRUG_INFO d on a.MZZY_SERIES_NO=d.MZZY_SERIES_NO join EMR_CONTENT e on a.MZZY_SERIES_NO=e.MZZY_SERIES_NO JOIN TEST_INFO A17 ON a.MZZY_SERIES_NO = A17.MZZY_SERIES_NO where a.PAT_AGE>='18' and (to_char(a.ADMIT_DATE,'YYYY-MM-DD') >= '2021-01-01') AND (b.DIAG_RESULT LIKE '%鼻咽癌%' or b.DIAG_RESULT LIKE '%鼻咽恶性肿瘤%' or b.DIAG_CODE LIKE '%C11/900%') and d.DRUG_NAME not in (select DRUG_NAME FROM DRUG_INFO WHERE DRUG_NAME like '卡培他滨') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%HIV阳性%') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%充血性心力衰竭%') AND to_char(( A17.TEST_DETAIL_ITEM_NAME = '中性粒细胞' AND A17.TEST_RESULT >= 1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血小板' AND A17.TEST_RESULT >= 100 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血红蛋白' AND A17.TEST_RESULT >= 9 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '丙氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '天门冬氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐清除率' AND A17.TEST_RESULT > 51 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐' AND A17.TEST_RESULT <=1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '凝血酶原时间' AND A17.TEST_RESULT <= 1.5 ))语句哪里有问题
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值