1012--the Best Rank

Source: Internet
Author: User

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:c-C P Rogramming Language, M-mathematics (calculus or Linear Algebra), and E-english. At the mean time, we encourage students by emphasizing on their best ranks – that's, among the four ranks with respect T o 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 is given as the following:

StudentID  C  M  E  A310101 98 (90310102) 84310103 94     91 91 91 91

Then the best ranks for all the students is the since the 1st one have done the best in C programming Language, While the 2nd one in mathematics, the 3rd one in 中文版, and the last one in average.

Input

Each input file contains the one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which is the total number of students, and the NUM ber of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which are a string of 6 digits, followed by the three integer grades (in th e range of [0]) of that student in the order of C, M and E. Then there is M lines, each containing a student ID.

Output

For each of the M students, print on one line, the best rank for him/her, and the symbol of the corresponding rank, Separat Ed by a space.

The priorities of the ranking methods is ordered as A > C > M > E. Hence if there is or more ways for A Stu Dent to obtain the same best rank, and the output the one with the highest priority.

If A student is isn't 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
The most valuable of the Test bank is really the data inside, the ranking does not consider the situation of equal rank will be wrong.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cctype>#include<cstdlib>#include<cmath>#include<string>#include<map>#include<Set>#include<queue>#include<vector>#include<stack>#include<cctype>using namespacestd;typedef unsignedLong Longull;#defineINF 0XFFFFFFFstructstu{intc,m,e,id,g[4]; DoubleA;} s[2001];intcmp1 (Stu A,stu B) {returnA.a>B.A;}intcmp2 (Stu A,stu B) {returnA.c>B.C;}intCmp3 (Stu A,stu B) {returnA.m>b.m;}intCmp4 (Stu A,stu B) {returnA.e>B.E;}intMain () {intX,y,n,m,i,j,k,ans; Charc,gg[4]={'A','C','M','E'}; CIN>>n>>m;  for(i=0; i<n;++i) {cin>>s[i].id>>s[i].c>>s[i].m>>S[I].E; S[I].A= (S[I].C+S[I].M+S[I].E)/3.0; } sort (S,s+N,CMP1); s[0].g[0]=1;  for(i=1; i<n;++i) {if(s[i].a==s[i-1].a) s[i].g[0]=s[i-1].g[0]; Elses[i].g[0]=i+1; } sort (S,s+N,CMP2); s[0].g[1]=1;  for(i=1; i<n;++i) {if(s[i].c==s[i-1].c) s[i].g[1]=s[i-1].g[1]; Elses[i].g[1]=i+1; } sort (S,s+N,cmp3); s[0].g[2]=1;  for(i=1; i<n;++i) {if(s[i].m==s[i-1].m) s[i].g[2]=s[i-1].g[2]; Elses[i].g[2]=i+1; } sort (S,s+n,cmp4); s[0].g[3]=1;  for(i=1; i<n;++i) {if(s[i].e==s[i-1].e) s[i].g[3]=s[i-1].g[3]; Elses[i].g[3]=i+1; }     for(i=0; i<m;++i) {cin>>x; Y=2001;  for(j=0; j<n;++j) {if(x==s[j].id) {                 for(k=0;k<4;++k) {if(y>S[j].g[k]) {y=S[j].g[k]; C=Gg[k]; }                }                 Break; }        }        if(j==N) cout<<"N /A"<<Endl; Elsecout<<y<<" "<<c<<Endl; }    return 0;}

1012--the Best Rank

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.