• 1012 The Best Rank


    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 CME and A - Average of 4 students are given as the following:

    1. StudentID C M E A
    2. 310101 98 85 88 90
    3. 310102 70 95 88 84
    4. 310103 82 87 94 88
    5. 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 Specification:

    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 CM and E. Then there are M lines, each containing a student ID.

    Output Specification:

    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:

    1. 5 6
    2. 310101 98 85 88
    3. 310102 70 95 88
    4. 310103 82 87 94
    5. 310104 91 91 91
    6. 310105 85 90 90
    7. 310101
    8. 310102
    9. 310103
    10. 310104
    11. 310105
    12. 999999

    Sample Output:

    1. 1 C
    2. 1 M
    3. 1 E
    4. 1 A
    5. 3 A
    6. N/A

    题目大意

    给你N个学生成绩的信息,求每个学生在所有学生当中,最好的排名是哪门成绩(或者平均成绩最好),如果排名有相同的情况,要按照指定的要求输出


    思路

    笨办法,对四种排名排序四次,并用map记录


    C/C++ 

    1. #include
    2. using namespace std;
    3. struct Student{
    4. int id,c,m,e,avg;
    5. }s;
    6. void OP(int n, map<int,int>& p);
    7. void print(int id);
    8. map<int,int> apr,C,M,E,A;
    9. vector box;
    10. int main()
    11. {
    12. int N,K;
    13. cin >> N >> K;
    14. for(int z=0;z
    15. cin >> s.id >> s.c >> s.m >> s.e;
    16. apr[s.id] = 1;
    17. s.avg = (s.c + s.m + s.e)/3;
    18. box.push_back(s);
    19. }
    20. OP(1,C);
    21. OP(2,M);
    22. OP(3,E);
    23. OP(4,A);
    24. while (K--){
    25. cin >> N;
    26. if(apr[N]) print(N);
    27. else puts("N/A");
    28. }
    29. return 0;
    30. }
    31. void print(int id){
    32. char ch = 'A';
    33. int result = A[id];
    34. if(C[id]'C';
    35. if(M[id]'M';
    36. if(E[id]'E';
    37. printf("%d %c\n",result,ch);
    38. }
    39. bool cmp1(Student x,Student y){ return x.c > y.c; }
    40. bool cmp2(Student x,Student y){ return x.m > y.m; }
    41. bool cmp3(Student x,Student y){ return x.e > y.e; }
    42. bool cmp4(Student x,Student y){ return x.avg > y.avg; }
    43. void OP(int n, map<int,int>& p){
    44. int score;
    45. switch (n) {
    46. case 1: sort(box.begin(),box.end(),cmp1);
    47. score=box.front().c;
    48. for(int z=0;zsize();){
    49. int op = 0;
    50. while (z+opsize() && box[z+op].c==score){
    51. p[box[z+op].id] = z+1;
    52. op++;
    53. }
    54. z += op ? op : 1;
    55. if(zsize()) score = box[z].c;
    56. }
    57. break;
    58. case 2:sort(box.begin(),box.end(),cmp2);
    59. score=box.front().m;
    60. for(int z=0;zsize();){
    61. int op = 0;
    62. while (z+opsize() && box[z+op].m==score){
    63. p[box[z+op].id] = z+1;
    64. op++;
    65. }
    66. z += op ? op : 1;
    67. if(zsize()) score = box[z].m;
    68. }
    69. break;
    70. case 3: sort(box.begin(),box.end(),cmp3);
    71. score=box.front().e;
    72. for(int z=0;zsize();){
    73. int op = 0;
    74. while (z+opsize() && box[z+op].e==score){
    75. p[box[z+op].id] = z+1;
    76. op++;
    77. }
    78. z += op ? op : 1;
    79. if(zsize()) score = box[z].e;
    80. }
    81. break;
    82. case 4: sort(box.begin(),box.end(),cmp4);
    83. score=box.front().avg;
    84. for(int z=0;zsize();){
    85. int op = 0;
    86. while (z+opsize() && box[z+op].avg==score){
    87. p[box[z+op].id] = z+1;
    88. op++;
    89. }
    90. z += op ? op : 1;
    91. if(zsize()) score = box[z].avg;
    92. }
    93. break;
    94. }
    95. }


  • 相关阅读:
    Allegro Design Entry HDL(OrCAD Capture HDL)窗口管理菜单详细介绍
    莫能菌素人血清白蛋白纳米粒Monensin-HSA|合成路线
    秋招过半零Offer怎么办?
    深交所、上交所、北交所、外汇交易中心、上期所官方接口说明及下载地址
    I.MX6ULL开发笔记(一)——环境搭建、镜像烧录、网络连接
    JavaWeb进阶案例-实现AJAX+Sevlet前后端分离开发
    C# 常用功能整合-2
    通用环形缓冲区 LwRB 使用指南
    Excel快捷键
    用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
  • 原文地址:https://blog.csdn.net/daybreak_alonely/article/details/127640148