博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1012 The Best Rank
阅读量:4541 次
发布时间:2019-06-08

本文共 3673 字,大约阅读时间需要 12 分钟。

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  A310101     98 85 88 90310102     70 95 88 84310103     82 87 94 88310104     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 (≤), 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 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

完了,英文不好会死人呀,看了别人的解释才知道,是找出每个学生在A,C,M,E中的最好排名

如果在A、C、M、E排序过程中遇到同样的分数,需要有相同的排名,
比如在A这一科上5个人的成绩分别是100,90,90,88,87的话,排名应该是1,2,2,4,5,
这一点需要格外留意,不然没有办法通过所有测试。

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 9 10 struct Data11 {12 string No;13 int num;14 int rank;15 };16 17 int main()18 {19 int N, M;20 cin >> N >> M;21 vectornums[4];//A C M E22 unordered_map
name;//用于学号查找23 for (int i = 0; i < N; ++i)24 {25 string No;26 int c, m, e;27 cin >> No >> c >> m >> e;28 name[No]++;29 nums[0].push_back({ No,(c + m + e) / 3,1 });30 nums[1].push_back({ No,c,1 });31 nums[2].push_back({ No,m,1 });32 nums[3].push_back({ No,e,1 });33 }34 for (int i = 0; i < 4; ++i)35 {36 sort(nums[i].begin(), nums[i].end(), [](Data d1, Data d2) { return d1.num > d2.num; });37 for (int j = 1; j < nums[i].size(); ++j)38 {39 if (nums[i][j].num == nums[i][j - 1].num)//处理相同分数40 nums[i][j].rank = nums[i][j - 1].rank;41 else42 nums[i][j].rank = j + 1;//要跳过相同排名43 }44 }45 46 for (int j = 0; j < M; ++j)47 {48 string No;49 cin >> No;50 int a, c, m, e;51 if (name[No] == 0)52 cout << "N/A" << endl;53 else54 {55 for (int i = 0; i < name.size(); ++i)56 {57 if (nums[0][i].No == No) a = nums[0][i].rank;58 if (nums[1][i].No == No) c = nums[1][i].rank;59 if (nums[2][i].No == No) m = nums[2][i].rank;60 if (nums[3][i].No == No) e = nums[3][i].rank;61 } 62 if (a <= c && a <= m && a <= e) cout << a << " " << "A" << endl;63 else if (c <= a && c <= m && c <= e) cout << c << " " << "C" << endl;64 else if (m <= a && m <= c && m <= e) cout << m << " " << "M" << endl;65 else cout << e << " " << "E" << endl; 66 }67 }68 return 0;69 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11179407.html

你可能感兴趣的文章
Django Form 的主要内置字段介绍
查看>>
如何写好一个UITableView
查看>>
XML文件生成C++代码(基于rapidxml)
查看>>
写代码,更需要设计代码
查看>>
iOS:修改项目名
查看>>
SpringCloud-Eureka
查看>>
double在输出为字符串的几种方法效率测试
查看>>
ArcGIS API for JavaScript 4.2学习笔记[14] 弹窗的位置、为弹窗添加元素
查看>>
电路基础
查看>>
jquery 对象与DOM对象转换
查看>>
DELPHI 调用系统 ADO 配置窗体 提高软件易用性
查看>>
Mongodb 命令及 PyMongo 库的使用
查看>>
div+css 兼容ie6 ie7 ie8 ie9和FireFox Chrome等浏览器方法(非原创)
查看>>
关于SDWebImage加载高清图片导致app崩溃的问题
查看>>
如何查看方法在哪里被调用
查看>>
HUE的自动化安装部署
查看>>
图片服务器(FastDFS)的搭建
查看>>
myBatis应用
查看>>
RuntimeError: DataLoader worker (pid 18255) is killed by signal: Killed.
查看>>
[PHP] 用AppServ一步到位安装PHP服务器
查看>>