当前位置: 首页 > news >正文

PAT A1012 The Best Rank

1012 The Best Rank

分数 25

作者 CHEN, Yue

单位 浙江大学

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


 * 对n名同学按成绩平均数,C语言,数学,英语成绩优先级逐级递减,分别按成绩从高到低
 * 进行排列,成绩相同者排名相同,平均成绩按四舍五入处理;
 * 先用一个结构体存储学生的名字,各科成绩,后面分别按各优先级处理各科成绩,以及各科
 * 成绩的排名;
 *
 * 最后用一个unordered_map 来存储每个学生的姓名,以及他最好的科目的成绩排名和最好的科目
 * 的成绩排名下标;
 * 最后输入m个学生处理,输出即可。
 *
 * 具体操作参见代码

/*** 对n名同学按成绩平均数,C语言,数学,英语成绩优先级逐级递减,分别按成绩从高到低* 进行排列,成绩相同者排名相同,平均成绩按四舍五入处理;* 先用一个结构体存储学生的名字,各科成绩,后面分别按各优先级处理各科成绩,以及各科* 成绩的排名;* * 最后用一个unordered_map 来存储每个学生的姓名,以及他最好的科目的成绩排名和最好的科目* 的成绩排名下标;* 最后输入m个学生处理,输出即可。* * 具体操作参见代码*/#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>using namespace std;typedef pair<int, int> PII;struct Grade
{string name;int soc[4];int rank[4];
};const int N = 1e4+10;
struct Grade stu[N];
unordered_map<string, PII> ump;int n, m;int flag = 0;//用一个flag变量对四个成绩进行排名,后面用一个for循环处理,真的很高明啊;
//我最开始用了四个for循环,眼睛都看痛了,又学到一招
bool cmp(Grade a, Grade b)
{return a.soc[flag] > b.soc[flag];
}int main()
{cin >> n >> m;for(int i=0; i<n; ++i){int a[4];double db = 0;cin >> stu[i].name;for(int j=1; j<4; ++j){cin >> stu[i].soc[j];db += stu[i].soc[j];}db /= 3;db += 0.5; //平均数四舍五入stu[i].soc[0] = db;  //soc[0]存储平均数}//对A,C,M,E 按成绩进行排序,从高到低排名,成绩相等并列排名for(flag = 0; flag < 4; ++flag){sort(stu, stu + n, cmp);int cur = 1;for(int i=0; i<n; ++i){if(i == 0 || stu[i].soc[flag] != stu[i-1].soc[flag])stu[i].rank[flag] = cur;elsestu[i].rank[flag] = stu[i-1].rank[flag];++cur;}}for(int i=0; i<n; ++i){int maxv = N, idx = 0;for(int j=0; j<4; ++j){if(stu[i].rank[j] < maxv){maxv = stu[i].rank[j];idx = j;}}ump[stu[i].name] = {idx, maxv};}string str[] = {"A", "C", "M", "E"};while(m--){string query;cin >> query;if(ump.find(query) == ump.end())puts("N/A");else{auto t = ump[query];cout << t.second << ' ' << str[t.first] << endl;}}return 0;
}

http://www.lryc.cn/news/63732.html

相关文章:

  • “我和AI抠图网站的秘密情缘“
  • 最多能打多少场比赛呢
  • 鸿蒙Hi3861学习二-程序烧录与日志输出
  • typescript Awaited<Type>教程用法
  • AES硬件运算单元
  • mulesoft MCIA 破釜沉舟备考 2023.04.28.26 (易错题)
  • k210单片机定时器的应用
  • linux0.12-7-1
  • 设置 文本框 自动填充背景颜色 为白色
  • Bitmap引起的OOM问题
  • 【JavaEE初阶】认识线程(Thread)
  • 自动化运维工具一Ansible Roles实战
  • json 中有递归parentId节点转 c#实体类时如何处理
  • 给大家介绍几个手机冷门但好用的小技巧
  • 2.3 定点乘法运算
  • C++每日一练:打家劫室(详解动态规划法)
  • Wireshark使用
  • 这才是 SpringBoot 统一登录鉴权、异常处理、数据格式 的正确姿势
  • Java面试题总结 | Java面试题总结6-MYSQL模块(持续更新)
  • Linux命令集(Linux文件管理命令--mv指令篇)
  • 不一样的 Git 之间 | GitLab vs GitHub vs Gitee vs GitCode
  • 海尔牵头IEEE P2786国际标准通过Sponsor投票并连任工作组主席
  • 倾斜摄影超大场景的三维模型的顶层合并的纹理压缩与抽稀处理技术分析
  • linux命令之iostat详解
  • 【C++】程序员必备知识:认识类与对象
  • python基础实战5-python基本结构
  • 移动端异构运算技术 - GPU OpenCL 编程(基础篇)
  • QString类方法和变量简介(全)
  • 中移链控制台对接4A平台功能验证介绍
  • 必知的Facebook广告兴趣定位技巧,更准确地找到目标受众