当前位置:网站首页>PAT serie a 1137 final grades
PAT serie a 1137 final grades
2022-08-02 17:04:00 【keyboard sonata】
For students studying "Data Structures" in MOOCs of Chinese universities, in order to obtain a certificate, they must first obtain at least 200 points for online programming assignments, and then obtain at least 60 points in the overall evaluation (out of 100 points)).
The calculation formula of the overall evaluation score is G=(Gmid−term×40%+Gfinal×60%), if Gmid−term>Gfinal; otherwise, the overall evaluation G is Gfinal.
Here Gmid−term and Gfinal are the student's midterm and final grades, respectively.
The problem now is that each exam produces a separate report card.
This question asks you to write a program to combine different transcripts into one.
Input format
The input gives 3 integers on the first line, P (the number of students who did online programming assignments), M (the number of students who took the midterm exam), N (the number of students who took the final exam).Three blocks of input follow.
The first block contains P online programming grades Gp;
The second block contains M midterm test scores Gmid−term;
The third block contains N final exam scores Gfinal.
Each grade occupies one line, the format is: student number score.
Where Student ID is English letters and numbers with no more than 20 characters; Score is a non-negative integer (the maximum total score for programming is 900, and the maximum score for mid-term and final is 100).
Output Format
Prints out the list of students who have received certificates.One line for each student in the format:
Student Number Gp Gmid−term Gfinal G
If some grades do not exist (eg someone did not take the midterm exam), output "−1" in the corresponding position.The output order is in descending order of the total score (rounded to the nearest whole number).
If there is a tie, it will be incremented by student number.
The question ensures that the student number is not duplicated and that there is at least 1 qualified student.
Data Range
1≤P,M,N≤10000
Input Example:
6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81
Example output:
missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84
My solution:
#include using namespace std;struct Student{string id;int p, m, f, s;Student(): p(-1), m(-1), f(-1), s(0){}void calc(){if(m > f) s = round(m*0.4 + f*0.6);else s = f;}bool operator< (const Student& t) const{if(s != t.s) return s > t.s;else{return id < t.id;}}};int main(){int p, m, n;cin >> p >> m >> n;unordered_map hash;string id;int s;for(int i = 0; i < p; i ++ ){cin >> id >> s;hash[id].id = id;hash[id].p = s;}for(int i = 0; i < m; i ++ ){cin >> id >> s;hash[id].id = id;hash[id].m = s;}for(int i = 0; i < n; i ++ ){cin >> id >> s;hash[id].id = id;hash[id].f = s;}vector students;for(auto per : hash){auto stu = per.second;stu.calc();if(stu.p >= 200 && stu.s >= 60) students.push_back(stu);}sort(students.begin(), students.end());for(auto re : students){cout << re.id << ' ' << re.p << ' ' << re.m << ' ' << re.f << ' ' << re.s << endl;}return 0;} Harvest:
Structure constructor initialization: Student(): p(-1), m(-1), f(-1), s(0){}
Define the internal function of the structure
边栏推荐
- JS本地存储(附实例)
- 解决(An error happened during template parsing (template: “class path resource [templates/...]
- The difference and connection between dist, pdist and pdist2 in MATLAB
- 一文让你快速写上扫雷游戏!童年的经典游戏,发给你的小女友让你装一波!!
- js中的数组方法和循环
- 《数字经济全景白皮书》银行业智能风控科技应用专题分析 发布
- 基于mobileNet实现狗的品种分类(迁移学习)
- 电设3----脉冲信号测试仪
- 2022-07-28 第六小组 瞒春 学习笔记
- 异常简单总结
猜你喜欢

【Leetcode字符串--字符串变换/进制的转换】HJ1.字符串最后一个单词的长度 HJ2.计算某字符出现次数 HJ30.字符串合并处理

servlet交互过程图详解,servlet的常见问题,创建web项目(一)

自定义属性

ShardingSphere基本介绍及核心概念

CNN鲜花分类

Impulse response invariant method and bilinear transformation method for IIR filter design

如何使用Swiper外部插件写一个轮播图

MySQL 的几种碎片整理方案总结(解决delete大量数据后空间不释放的问题)

JS本地存储(附实例)

类加载过程
随机推荐
XGBoost 和随机森林在表格数据上优于深度学习?
Servlet基础详解
JS本地存储(附实例)
对象和类总结
遍历堆 PAT甲级 1155 堆路径
从零开始的循环之旅(上)
【无标题】
2022-07-19 第五小组 瞒春 学习笔记
太香了!阿里Redis速成笔记,从头到尾全是精华!
【 Leetcode string, the string transform/hexadecimal conversion 】 HJ1. The length of the string last word HJ2. Calculation of a certain number of characters appear HJ30. String merging processing
lambda表达式、Stream接口及Optional类
容器中的Cgroup
2022-07-09 第五小组 瞒春 学习笔记
我的第一篇博客
servlet交互过程图详解,servlet的常见问题,创建web项目(一)
为什么四个字节的float表示的范围比八个字节的long要广?
一文让你快速手写C语言-三子棋游戏
《数字经济全景白皮书》银行业智能风控科技应用专题分析 发布
什么是Nacos?
状态码以及访问百度过程