首页 > 其他分享 >1012 The Best Rank (25分)

1012 The Best Rank (25分)

时间:2022-08-27 23:45:41浏览次数:58  
标签:25 Student s2 s1 Rank student 91 id Best

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:

StudentID  C  M  E  A
310101     98 85 88 90
310102     70 95 88 84
310103     82 87 94 88
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:

5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999

 

Sample Output:

1 C
1 M
1 E
1 A
3 A
N/A
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 struct Student{
 4     int id,c,m,e;
 5     float a;
 6 }student[2005];
 7 bool CmpByA(Student s1,Student s2){
 8     return s1.a>s2.a;
 9 }
10 bool CmpByC(Student s1,Student s2){
11     return s1.c>s2.c;
12 }
13 bool CmpByM(Student s1,Student s2){
14     return s1.m>s2.m;
15 }
16 bool CmpByE(Student s1,Student s2){
17     return s1.e>s2.e;
18 }
19 
20 int main(){
21     int n,m,k;
22     vector<vector<int>> v(1000000); //存储排名信息,第一维是学号,第二维是学科排名,其中0、1、2、3分别表示a、c、m、e,如v[id][0]表示学号为id的同学的平均成绩排名
23     set<int> s;  //单纯收集id用来判断该学号是否有效
24     cin>>n>>m;
25     for(int i=0;i<n;++i){
26         cin>>student[i].id
27             >>student[i].c
28             >>student[i].m
29             >>student[i].e;
30         s.insert(student[i].id);
31         v[student[i].id].resize(5);
32         student[i].a=(student[i].c+student[i].m+student[i].e)/3;
33     }
34     sort(student,student+n,CmpByA);
35     v[student[0].id][0]=1;
36     for(int i=1;i<n;++i){
37         if (student[i].a==student[i-1].a){  //判断是否并列,若和上一名同学并列则继承其排名
38             v[student[i].id][0]=v[student[i-1].id][0];
39         }
40         else{   //不并列则按照正常排名来
41             v[student[i].id][0]=i+1;
42         }
43     }
44     sort(student,student+n,CmpByC);
45     v[student[0].id][1]=1;
46     for(int i=1;i<n;++i){
47         if (student[i].c==student[i-1].c){
48             v[student[i].id][1]=v[student[i-1].id][1];
49         }
50         else{
51             v[student[i].id][1]=i+1;
52         }
53     }
54     sort(student,student+n,CmpByM);
55     v[student[0].id][2]=1;
56     for(int i=1;i<n;++i){
57         if (student[i].m==student[i-1].m){
58             v[student[i].id][2]=v[student[i-1].id][2];
59         }
60         else{
61             v[student[i].id][2]=i+1;
62         }
63     }
64     sort(student,student+n,CmpByE);
65     v[student[0].id][3]=1;
66     for(int i=1;i<n;++i){
67         if (student[i].e==student[i-1].e){
68             v[student[i].id][3]=v[student[i-1].id][3];
69         }
70         else{
71             v[student[i].id][3]=i+1;
72         }
73     }
74     for (int i=0;i<m;i++){
75         cin>>k;
76         if (s.find(k)!=s.end()){
77             int index=0;
78             for(int j=1;j<4;++j){
79                 if (v[k][j]<v[k][index]){
80                     index=j;
81                 }
82             }
83             switch(index){
84                 case 0:cout<<v[k][index]<<" A"<<endl;break;
85                 case 1:cout<<v[k][index]<<" C"<<endl;break;
86                 case 2:cout<<v[k][index]<<" M"<<endl;break;
87                 case 3:cout<<v[k][index]<<" E"<<endl;break;
88             }
89         }
90         else{
91             cout<<"N/A"<<endl;
92         }
93     }
94 }

 

tip:

1.这题我挂在2、3测试点,这两个测试点考察的是对于并列名次的处理,在生成排名时添加并列逻辑即可

2.申请二维vector时,需要声明第一维度的大小,且用v[i].resize(n)来开辟第二维的大小,否则会提示段错误,当然这题可以用其他更合理的数据结构来存储排名。

 

标签:25,Student,s2,s1,Rank,student,91,id,Best
From: https://www.cnblogs.com/coderhrz/p/16631813.html

相关文章

  • 2022-08-25 第二小组 张鑫 学习笔记
    实训四十七天元素操作BOM1.学习内容自定义属性设置元素属性<divhaha="abc"id="xyz"></div><script>letdiv=document.querySelector("div");//......
  • WDA学习(25):DateNavigator使用
    1.18UIElement:DateNavigator使用本实例测试创建DateNavigator;1.创建Component,View:V_DATE_NAVIGATOR;2.创建Context节点;创建NODE:NODE_DATENAV,Cardinality:......
  • 洛谷 P2582 函数
    函数-洛谷可以发现性质\(g(f^m(x))=f^m(g(x))\)。若设左侧\(x\)所在环大小为\(size(x)\),右侧\(g(x)\)所在环的大小为\(size(gx)\)。可以得到,\(size(gx)\mid......
  • 2022-8-25 第四组 曹雨 Java script HTML元素操作,BOM
    对HTML元素的操作获取某个元素的属性的值:方法1:元素.属性名特别注意:元素.属性名的方式只适用于元素原生的属性,自定义的属性是拿不到的例子:console.log(div.id)方法2:......
  • 0825 思维题两则
    0825思维题两则感觉总得写点题解记录一下,但是不想记录的太复杂,记录一下策略吧解的好和讲的好是两回事,我毕竟解的都不好,也就没人看了,所以记得简略一点,不求讲的好了Fib......
  • CTFSHOW Web259 SoapClient原生类的反序列化
      index.php   看到该题目第一眼,大脑直接一个简单的想法就是通过访问flag.php添加X-Forwarded-For然后POST发送token数据。但!在本题的环境当中,由于使用了Clou......
  • AT2580 题解
    前言题目传送门!更好的阅读体验?这题是常规的二分答案。前置知识:二分答案教大家一个小技巧:如何判断一题是否可以使用二分答案,以及如何编写程序?设计\(f(x)\)函数,确......
  • 2022 8 25
    只做了一个组队题目https://www.lanqiao.cn/problems/604/learning/报错是因为s1,s2里面的内容被更改,于是超出列表范围了。具体的周末整理的时候再说。importosimport......
  • 【2022.8.25】前端开发(4)
    学习内容概要JS基本数据类型流程控制函数与面向对象JS的BOM与DOM操作学习内容详细JS数据类型之布尔值1.回顾之前python中布尔值(bool)TrueFalse:0None[]......
  • 825(json,正则)
    json数据json是存储数据的一种格式JavascriptObjectNotation(JavaScript对象表示法)json是存储和交换文本信息的语法,类似XML,JSON比XML更小,更快更易解析什么是JSONJ......