1012. The best Rank (25)

Source: Internet
Author: User
1012. The best Rank (+)Time limit MS
Memory Limit 65536 KB
Code length limit 16000 B
Program Standard author CHEN, Yue

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  A
310101     98-
310102     94 88 (310103 82 87)
310104     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 6 310101 98, 310102, 310103, and 94 310104, 310105
310 102
310103
310104
310105
999999
Sample Output
1 C
1 M
1 E
1 A
3 a
N/a
Main ideas:
1. Use map CV to contact the student ID and input sequence number
2, the ranking is the actual ranking, if there are 2 first, there is no 2nd place
3. Use a two-dimensional array to store each student's per-class and average scores (no need to do so, check which students go to search this student's ranking is good)
4, this code through Pat all test points, but a test point on the cattle online can not pass, why.
#include <iostream> #include <string> #include <map> using namespace std;  #define MAX_N 2001 void Rank_per_project (int* array,int flag,int n,int (*id) [6])//Place the rank of each student in a single account into the flag bit {int of the Id two-dimensional array
    Temp=0,count=1;
        for (int i=0; i<n; ++i) {temp=array[i];
        Count=1;
            for (int k=0; k<n; ++k) {if (array[k]>temp) {count++;
    }} Id[i][flag]=count; }} void Rank (int *c,int *m,int* e,int*a,int (*id) [6],int n,string str) {rank_per_project (c,1,n,id);  Name, and deposit the student Id array rank_per_project (M,2,N,ID); The ranking of each student's M-subject score is processed and deposited in the student Id array rank_per_project (E,3,N,ID); The ranking of each student's e-subject score is processed and deposited in the student Id array rank_per_project (A,0,N,ID);
    Rank each student's average score and deposit the student ID array int rank=n+1;
    int flag=-1;
        for (int i=0; i<n; ++i)//handling the best rankings for each student and depositing id[][4],id[][5] into the flag, each row of the Id two-dimensional array is placed in the course priority, and the lower priority account must be ranked better in order to record the best ranking for that student {
        rank=n+1; for (int k=0; k<4;
                ++k) {if (Id[i][k]<rank) {rank=id[i][k];
            Flag=k;
        }} Id[i][4]=rank;
    Id[i][5]=flag;
    }} int main (int argc, const char * argv[]) {int n,m;
    
    cin>>n>>m;
    int c[max_n]={0};
    int m[max_n]={0};
    int e[max_n]={0};
    int a[max_n]={0};
    
    int id[max_n][6]={0};
    Map<string,int> relation;//creates an association between each student ID and the input sequence number to facilitate subsequent processing of the string ID;
        for (int i=0; i<n; ++i) {cin>>id>>c[i]>>m[i]>>e[i];
        A[i]=c[i]+m[i]+e[i];
    Relation[id]=i;
    } string str= "ACME";
    Rank (C, M, E, A,ID,N,STR);
    
    
    
    Map<string,int>::iterator it;
    String Search[max_n];
    int sequence=0;
    for (int i=0; i<m; ++i) {cin>>search[i];
        } for (int i=0; i<m; ++i) {it=relation.find (search[i]); if (It!=relation.end ())//Successful SearchTo the student {sequence=it->second;
        cout<<id[sequence][4]<< ' <<str[Id[sequence][5]]<<endl;;
        }else//did not find the student information {cout<< "n/a" <<endl;
}} return 0;
 }


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.