写完后又参考其他人的写法修改了一下:发现既然只有取得final exam成绩的学生才有最终成绩,那在42行到54行代码中,完全可以把最终成绩算出来(没有进行final exam的学生无最终成绩,不进入最终的排序)。

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>struct stu {std::string id;int Gp = -1;int Gmid = -1;int Gfinal = -1;int g = -1;stu(std::string _id) : id(_id) {}
};int P, M, N, grade, cnt;
std::string id;
std::vector<stu> vec, result;
std::unordered_map<std::string, int> students;bool cmp(const stu &a, const stu &b) {return a.g != b.g ? a.g > b.g : a.id < b.id;
}int main() {std::cin >> P >> M >> N;cnt = 0;for (int i = 0; i < P; ++i) {std::cin >> id >> grade;if (grade >= 200) {students.insert({id, cnt++});vec.push_back(stu(id));vec[vec.size() - 1].Gp = grade;}}for (int i = 0; i < M; ++i) {std::cin >> id >> grade;if (students.find(id) != students.end()) {vec[students[id]].Gmid = grade;}}for (int i = 0; i < N; ++i) {std::cin >> id >> grade;if (students.find(id) != students.end()) {stu curr = vec[students[id]];curr.Gfinal = grade;if (curr.Gmid > grade) {curr.g = 0.4 * curr.Gmid + 0.6 * grade + 0.5;} else {curr.g = grade;}result.push_back(curr);}}sort(result.begin(), result.end(), cmp);for (int i = 0; i < result.size(); ++i) {if (result[i].g >= 60) {std::cout << result[i].id << " " << result[i].Gp << " " << result[i].Gmid<< " " << result[i].Gfinal << " " << result[i].g << std::endl;}}return 0;
}

题目如下:

For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a final grade no less than 60 out of 100. The final grade is calculated by G=(Gmid−term​×40%+Gfinal​×60%) if Gmid−term​>Gfinal​, or Gfinal​ will be taken as the final grade G. Here Gmid−term​ and Gfinal​ are the student's scores of the mid-term and the final exams, respectively.

The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one.

Input Specification:

Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the mid-term list; and N, the number of students on the final exam list. All the numbers are no more than 10,000.

Then three blocks follow. The first block contains P online programming scores Gp​'s; the second one contains M mid-term scores Gmid−term​'s; and the last one contains N final exam scores Gfinal​'s. Each score occupies a line with the format: StudentID Score, where StudentID is a string of no more than 20 English letters and digits, and Score is a nonnegative integer (the maximum score of the online programming is 900, and that of the mid-term and final exams is 100).

Output Specification:

For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format:

StudentID Gp​ Gmid−term​ Gfinal​ G

If some score does not exist, output "−1" instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their StudentID's. It is guaranteed that the StudentID's are all distinct, and there is at least one qullified student.

1137 Final Grading (PAT 甲级)相关推荐

  1. PAT甲级1137 Final Grading:[C++题解]结构体、排序、哈希表、结构体构造函数、结构体内写函数

    文章目录 题目分析 题目链接 题目分析 分析: 首先一个学生有id,另外有4个成绩:编程成绩.期中成绩.期末成绩.总评成绩.现有3个成绩单:编程成绩.期中成绩.期末成绩,让计算总评成绩,并排序输出. ...

  2. PAT甲级1141 PAT Ranking of Institutions :[C++题解]结构体、排序、哈希表、结构体构造函数、结构体内写函数、排名

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:和下面这题是一道题: PAT甲级1137 Final Grading:[C++题解]结构体.排序.哈希表.结构体构造函数.结构体内写函 ...

  3. 2020年9月PAT甲级满分必备刷题技巧

    2020年7月的考试结束了,除了本次的考题更新,短期内不会更新. [7月题目的特点:首次线上考试,没出链表.树相关的模板题,第2到4题背景新颖,大大降低了抄袭历年代码的可能性,可以看作是线上考试的新趋 ...

  4. 【PAT甲级真题整理五】1121~1155

    终于考完了qaq把最后一堆也整理出来了 目录 1121 Damn Single(25)set.map的使用 1122 Hamiltonian Cycle(25)哈密顿回路 1123 Is It a C ...

  5. 刷PAT甲级的各题思路、细节以及遇到的问题记录

    1001 A+B Format (20分) 因为一定会用到字符串,而string非常好用,但是用的时候一定要注意不能越界访问,否则会在运行时出现abort() has been called. 100 ...

  6. PAT甲级题目翻译+答案 AcWing(哈希表)

    1048 Find Coins (25 分) 题意 : 给一序列,要求从中选出两个值使得它们的和恰好等于m,输出第一个值字典序最小且升序的方案 思路 : 看似O(n2)O(n^2)O(n2),其实可以 ...

  7. PAT 甲级-算法初步

    阅读原文 接上一篇 PAT 甲级-入门模拟 ,自我感觉这部分才是真正的算法入门,对基础的数据结构提供了很好的类型题进行匹配练习 包括分类:排序.散列.贪心.二分.双指针.打表.递推 排序 思想解释 排 ...

  8. 【PAT甲级】A1101-A1155刷题记录

    文章目录 (递推) A1101 Quick Sort (25 分) 0.23 (静态二叉树+遍历) A1102 Invert a Binary Tree (25 分) 0.51 (数学问题) A110 ...

  9. PAT甲级 1056

    PAT甲级 1056 题目 Mice and Rice 解析 代码 题目 Mice and Rice Mice and Rice is the name of a programming contes ...

最新文章

  1. MySQL设计一个图书馆数据库_请设计一个图书馆数据库
  2. Python-生成模拟原始脑电数据
  3. es中的AllocationService
  4. 多人开发时Git下冲突的产生和解决
  5. 强化学习(四)—— Actor-Critic
  6. 漫步者蓝牙驱动_2020年知乎最受欢迎的高性价比真无线蓝牙耳机推荐,轻松选择蓝牙耳机(9月最新)!...
  7. subversion安装与配置备忘录
  8. [如何做研究][如何写论文]
  9. element el-tree 懒加载 默认展开第二层
  10. GTK的.NET的函数库 GTK#
  11. 网关监控软件设计与实现
  12. Docker--一门值得你学习的手艺
  13. Rayman的绝顶之路——Leetcode每日一题打卡10
  14. 使用股指期货与ETF基金进行期现套利
  15. 车载娱乐系统开发术语记录
  16. ios10 上下黑边问题
  17. 中国与美国光纤网络连接详解
  18. 【Java获取国家法定节假日三种工具类其二】
  19. 如何在 Linux 中查找一个文件
  20. 什么品牌的蓝牙耳机音质最好?高品质蓝牙耳机排行榜

热门文章

  1. 基于stm32f103zet6之DS18B20的学习
  2. RFID定位技术系统的实际应用
  3. Python实现ANN与KNN的图像分类
  4. ubuntu命令 图片 壁纸_ubuntu壁纸软件
  5. 免费的预装正版Office家庭和学生版失效解决方法
  6. GD32E230 printf 之 J-LINK RTT Viewer
  7. 基于JSP+Servlet+MySQL实现实验管理系统
  8. 国标结构专业图集大全 电子版
  9. Shader 能量法球特效
  10. 苹果x有android文件夹,iOS有大变化:新增像安卓手机的文件管理夹