1012. The Best Rank (25)[C语言实现]
来源:互联网 发布:java医院管理系统 编辑:程序博客网 时间:2024/06/06 20:27
1012. The Best Rank (25)
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 Input5 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999Sample Output
1 C1 M1 E1 A3 AN/A
注意:1)当分数一样时排名一样 2)注意优先级 3)排名是按照每个科目排名 取排名最前的 就是序号最小 下面是AC代码:
#include <stdio.h> #include <stdlib.h>typedef struct Student{char id[6] ;int a[4];char max;int maxrank ;int rank[4];}stu;static char type[4] = {'A','C','M','E'};static int n,m;static stu stus[2005];static char s[2005][6]; int compareid(char id[],char a[]){int i;for(i = 0 ; i < 6 ; i++ ){if(id[i]<a[i]){return -1;}else if(id[i]>a[i]){return 1;} } return 0;}void sort(){int i , j , k ;for(i = 3 ; i >= 0 ; i--){for(j = 0 ; j < n ; j++){for(k = j+1 ; k < n ; k++){if(stus[j].a[i] < stus[k].a[i]){stu t = stus[j];stus[j] = stus[k];stus[k] = t ;}}if(j>0 && stus[j-1].a[i] == stus[j].a[i] ){stus[j].rank[i] = stus[j-1].rank[i];}else{stus[j].rank[i] = j + 1;}}}}void getMaxrank(){int i , j ;for(i = 0 ; i < n ; i++){stus[i].maxrank = stus[i].rank[0];int maxindex = 0;for(j = 1 ; j < 4 ; j++){if(stus[i].maxrank > stus[i].rank[j]){stus[i].maxrank = stus[i].rank[j];maxindex = j;}}stus[i].max = type[maxindex];}}void check(int a){int i ,sum,avg,j;for(i = 0 ; i < n ; i++){if(compareid(stus[i].id,s[a])==0){printf("%d %c\n",stus[i].maxrank,stus[i].max); return ;}}printf("N/A\n");} int checkexist(char a[],int i){int j = 0;for(j =0; j<i ; j++){if(compareid(a,stus[j].id)==0){return 1 ;}}return 0 ;}int main(){int i,sum;scanf("%d %d",&n,&m);for(i = 0 ; i < n ; i++){scanf("%s %d %d %d",&stus[i].id,&stus[i].a[1],&stus[i].a[2],&stus[i].a[3]); if(checkexist(stus[i].id,i)==1){i--;n--;continue;}sum = stus[i].a[1]+stus[i].a[2]+stus[i].a[3];stus[i].a[0] = sum/3.00;}sort();getMaxrank(); for(i = 0 ; i < m ; i++){scanf("%s",&s[i]); }for(i = 0 ; i < m ; i++){ check(i);}return 0 ;}
- 1012. The Best Rank (25)[C语言实现]
- 【C++】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)
- InSAR Processing Wiki
- 浅析TCP与UDP
- DeepLearning tutorial——CNN卷积神经网络应用于人脸识别(详细流程+代码实现)
- 用友 uap nc65开发编码树改为pk树方法
- JavaScript实现拖拽预览,AJAX小文件上传
- 1012. The Best Rank (25)[C语言实现]
- jsp之ajax的初次应用
- 虚拟机上的ubuntu安装VMware Tools问题
- Java入门学习-学习if & else,for循环,foreach循环,while循环的用法。
- 幂等性的理解
- hector_mapping添加imu
- 简单说说如何测试内存泄漏
- Python Notes (1)
- Django中项目目录下的settings.py中STATIC_URL配置的路径对所有应用都生效