1012. The Best Rank (25)
来源:互联网 发布:浙江大学知乎 编辑:程序博客网 时间:2024/06/14 22:26
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
/** 2017.3.10 Donald*///1012. The Best Rank (25)/** 题意: 找到最好成绩,按 A > C > M > E,输出:科目 排名 如果 不在榜上, 则输出 N / A 思路:*/#include<cstdio>#include<iostream>using namespace std;#define MAXN 2001struct Student { int id; int C; int M; int E; int A; char subject; int bestRank;};int N, Mi;Student student[MAXN];int main(void) { int A, C, M, E, id; scanf("%d%d", &N, &Mi); for (int i = 0; i < N; ++i) { scanf("%d%d%d%d", &id, &C, &M, &E); student[i].id = id; student[i].C = C; student[i].M = M; student[i].E = E; student[i].A = (C + M + E) / 3; } for (int i = 0; i < N; ++i) { int Arank = 1, Mrank = 1, Crank = 1, Erank = 1; for (int j = 0; j < N; ++j) { if (student[i].A < student[j].A) Arank ++; if (student[i].C < student[j].C) Crank ++; if (student[i].M < student[j].M) Mrank ++; if (student[i].E < student[j].E) Erank ++; } student[i].bestRank = Arank; student[i].subject = 'A'; if (Arank > Crank) { student[i].bestRank = Crank; student[i].subject = 'C'; } if (Crank > Mrank && Arank > Mrank) { student[i].bestRank = Mrank; student[i].subject = 'M'; } if (Mrank > Erank && Crank > Erank && Arank > Erank) { student[i].bestRank = Erank; student[i].subject = 'E'; } } int flag = 0; for (int i = 0 ; i < Mi; ++i) { scanf("%d", &id); flag = 0; for (int j = 0; j < N; ++j) { if (student[j].id == id) { printf("%d %c\n", student[j].bestRank, student[j].subject); flag = 1; break; } } if (flag){ continue; } printf("N/A\n"); } return 0;}
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- Threes.js入门篇之7
- 重载和覆盖
- gradle简单模板
- 升级高版本的struts2.2.3.32 无法访问Action解决办法
- hello world漫游
- 1012. The Best Rank (25)
- 好一道深搜
- 《图解HTTP》读书笔记05
- Threes.js入门篇之8
- Java 7的6个新特性
- Python学习(1)
- union联合 数据类型 详细说明
- APP开发问题汇总
- 有些事情想灵光一样,如果不当时就记住, 过一会儿就想不起来。