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

PAT 甲级 1012 The Best Rank(25)

时间:2023-03-16 21:33:54浏览次数:35  
标签:25 PAT int Rank stu score students 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 C, M, E 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 C, M 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

Experiential Summing-up

1、用结构体储存比较方便

2、输入完学生信息(学号、成绩)后将每门课按成绩排序,并处理并列情况——排名并列应该为1、1、3、4、5,而不是1、1、2、3、4

3、然后寻找每位学生的最高排名并输出

4、其他注意事项在代码中注释

Accepted Code

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n, m, id, flag = -1;
 4 char c[4] = {'A', 'C', 'M', 'E'};
 5 int exist[1000000]; //用来保存当前id是否存在
 6 struct node
 7 {
 8     int id, best;//best记录最好的科目是哪一门(0、1、2、3)
 9     int score[4], rank[4];
10 }stu[2005];
11 
12 bool cmpl(node a, node b)
13 {
14     return (a.score[flag] > b.score[flag]);
15 }
16 
17 int main()
18 {
19     cin >> n >> m;
20     for(int i = 0; i < n; i ++)
21     {
22         cin >> stu[i].id >> stu[i].score[1] >> stu[i].score[2] >> stu[i].score[3];
23         stu[i].score[0] = (stu[i].score[1] + stu[i].score[2] + stu[i].score[3]) / 3.0;
24     }
25     for(flag = 0; flag <= 3; flag ++)
26     {
27         sort(stu, stu + n, cmpl);
28         stu[0].rank[flag] = 1; //令排序后第一位同学的第flag门成绩排名第一
29         for(int i = 1; i < n; i ++)
30         {
31             stu[i].rank[flag] = i + 1; //后面同学排名依次+1
32             if(stu[i].score[flag] == stu[i-1].score[flag]) //处理并列情况
33                 stu[i].rank[flag] = stu[i-1].rank[flag];
34         }
35     }
36     for(int i = 0; i < n; i ++)
37     {
38         exist[stu[i].id] = i + 1; //因为下面需要判断temp!=0,所以exist从第一位开始存
39         stu[i].best = 0;
40         int minn = stu[i].rank[0];
41         for(int j = 1; j <= 3; j ++) //1?
42         {//寻找每位学生的最高排名
43             if(stu[i].rank[j] < minn)
44             {
45                 minn = stu[i].rank[j];
46                 stu[i].best = j;
47             }
48         }
49     }
50     for(int i = 0; i < m; i ++)
51     {
52         cin >> id;
53         int temp = exist[id];
54         if(temp)
55         {
56             int best = stu[temp-1].best; //temp-1与结构体对应
57             cout << stu[temp-1].rank[best] << " " << c[best] << endl;
58         }
59         else cout << "N/A" << endl;
60     }
61     return 0;
62 }

 

标签:25,PAT,int,Rank,stu,score,students,id,best
From: https://www.cnblogs.com/marswithme/p/17220162.html

相关文章

  • 【洛谷】P2257 YY的GCD(莫比乌斯反演)
    原题链接题意\(T\)组询问,每次询问求:\[\sum_{i=1}^{n}\sum_{i=1}^{m}[\gcd(i,j)\inprime]\]\(T=10^4,n,m\leq10^7\)。思路不难想到枚举质数,将原式化简为:\[\sum......
  • PAT Basic 1030. 完美数列
    PATBasic1030.完美数列1.题目描述:给定一个正整数数列,和正整数\(p\),设这个数列中的最大值是\(M\),最小值是\(m\),如果\(M≤mp\),则称这个数列是完美数列。现在给定......
  • PAT Basic 1029. 旧键盘
    PATBasic1029.旧键盘1.题目描述:旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏......
  • 1425. 带限制的子序列和
    题目描述数组值可以是负,需要返回一个非空的子序列和的最大值。其中对子序列的要求是相邻两个元素的原始下标不能超过kf1-dp+单调队列优化基本分析1.怎么联想到dp?对某......
  • vuex TypeError: Cannot read properties of undefined (reading ‘dispatch‘)
      1、入口文件main.js  2、或者版本不匹配 vue2安装3版本的vuex,默认安装的4版本给vue3用//卸载原来安装的vuexnpmuninstallvuex//安装3.6.2版本的vuexnpm......
  • 使用patch-package定制node_modules 中的依赖包
    背景:首先,需求是这样,Vue项目中使用的是iview第三方UI库,要修改组件DatePicker中默认选中的当日的日期(如下图),实现无论在哪个时区,均显示中国的日期   由于,iview提供的a......
  • 【825】journal abbreviation elsevier,投稿杂志缩写查找
    https://jcr-clarivate-com.wwwproxy1.library.unsw.edu.au/jcr/browse-journals(B站有个视频)直接Google查询方法三:search ......
  • 25-设计模式总结
    25-设计模式总结分类设计模式可以分为3类:创建型模式结构型模式行为型模式创建型模式抽象工厂模式提供一个创建一系列或相关依赖对象的接口,而无需指定他们具体的类......
  • Vue.js 监视属性(p20~p25)
    视频21视频22视频23视频24视频25天气案例<!DOCTYPEhtml><html> <head> <metacharset="UTF-8"/> <title>天气案例</title> <!--引入Vue--> <scriptty......
  • singleton pattern
    C1.overviewp1.conceptproblemsPeoplecanusereflectmechanismtocreateotherinstancetoviolatesingleton.ThesafetyofthreadInstructionreordering......