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 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 91Then 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.
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.
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.
用结构体存放学生的数据,string类型存放学生id,best存放学生排名最好的科目(科目的优先级是A>C>M>E),所以best就是对应这个优先级字符的下标,scores[4]表示学生4门成绩,注意用scores[0]存放平均分,rank[4]对应于4门成绩的排名。
此外,用map判断是学生是否存在成绩,键值对为(id,下标);存放下标是为了记录学生在students[2000]数组里面的位置,因为每次排序后位置都会发生变化
自定义的cmp比较函数,sort的第三个参数是比较函数,该函数只能传入两个参数,所以定义一个全局index传入方便比较学生的各个成绩
map的插入方式:
exist.insert(pair<string,int>(students[i].stu_id, i)); // 记录students数组的下标map的判断是否存在key:如果存在key,count函数则返回1,否则返回0
(exist.count(id) !=0){注意点:
学生单门的成绩相同时的排名,例如1,1,3,4,5而不是1,1,2,3,4。对于平均分,不用四舍五入也能通过样例,PAT和牛客网(id是字符串)均可