A1137. Final Grading
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 "−" 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.
Sample Input:
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
Sample Output:
missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef struct NODE{
string id;
int Gp, Gm, Gf, G, valid;
NODE(){
Gp = -;
Gm = -;
Gf = -;
}
}info;
map<string, int> mp;
int pt = ;
info stu[];
bool cmp(info a, info b){
if(a.valid != b.valid){
return a.valid > b.valid;
}else{
if(a.G != b.G)
return a.G > b.G;
else{
return a.id < b.id;
}
}
}
int main(){
int P, M, N;
scanf("%d%d%d", &P, &M, &N);
for(int i = ; i < P; i++){
string ss;
int gp, index;
cin >> ss >> gp;
if(mp.count(ss) == ){
mp[ss] = pt++;
index = pt - ;
}else index = mp[ss];
stu[index].Gp = gp;
stu[index].id = ss;
}
for(int i = ; i < M; i++){
string ss;
int mm, index;
cin >> ss >> mm;
if(mp.count(ss) == ){
mp[ss] = pt++;
index = pt - ;
}else index = mp[ss];
stu[index].Gm = mm;
stu[index].id = ss;
}
for(int i = ; i < N; i++){
string ss;
int gn, index;
cin >> ss >> gn;
if(mp.count(ss) == ){
mp[ss] = pt++;
index = pt - ;
}else index = mp[ss];
stu[index].Gf = gn;
stu[index].id = ss;
}
int cnt = ;
for(int i = ; i < pt; i++){
double temp = ;
if(stu[i].Gp < || stu[i].Gf == -){
stu[i].valid = -;
continue;
}
if(stu[i].Gm > stu[i].Gf){
temp = 0.6 * stu[i].Gf + 0.4 * stu[i].Gm + 0.5;
stu[i].G = (int)temp;
}else stu[i].G = stu[i].Gf;
if(stu[i].G >= && stu[i].G <= ){
stu[i].valid = ;
cnt++;
}
else stu[i].valid = -;
}
sort(stu, stu + pt, cmp);
for(int i = ; i < cnt; i++){
cout << stu[i].id << " " << stu[i].Gp << " " << stu[i].Gm << " " << stu[i].Gf << " " << stu[i].G << endl;
}
cin >> N;
return ;
}
总结:
1、由于学生id是字母型,需要使用map来保存id到数组下标的映射。
2、计算G时出现小数需要向上取整,可以(int)(计算结果+0.5)。
A1137. Final Grading的更多相关文章
- PAT A1137 Final Grading (25 分)——排序
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PAT甲级——A1137 Final Grading【25】
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PAT_A1137#Final Grading
Source: PAT A1137 Final Grading (25 分) Description: For a student taking the online course "Dat ...
- PAT 1137 Final Grading[一般][排序]
1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...
- PAT 甲级 1137 Final Grading
https://pintia.cn/problem-sets/994805342720868352/problems/994805345401028608 For a student taking t ...
- 1137 Final Grading (25 分)
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PAT 1137 Final Grading
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- 1137 Final Grading
题意:排序题. 思路:通过unordered_map来存储考生姓名与其成绩信息结构体的映射,成绩初始化为-1,在读入数据时更新各个成绩,最后计算最终成绩并把符合条件的学生存入vector,再排序即可. ...
- PAT (Advanced Level) Practice(更新中)
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
随机推荐
- hive权限配置
基于CDH5.x的Hive权限配置 1.打开权限控制,默认是没有限制的 set hive.security.authorization.enabled=true; 2.配置默认权限 hive.secu ...
- liunx安装nginx
参考 https://blog.csdn.net/dyllove98/article/details/41120789 1,去官网下载最新的包 官网地址:http://nginx.org/downlo ...
- mysql逻辑架构
逻辑架构图 MySQL有点与众不同,它的逻辑架构可以在多种不同的场景中应用并发挥良好的作用.主要体现在存储引擎的架构上,插件式的存储引擎架构将查询处理和其他的系统任务以及数据的存储提取相分离.这种架构 ...
- CentOS7装Tomcat
有两种安装方式:(1)yum 命令 (2)安装包 本次采用第二种方式: 1.windos下载apache-tomcat-7.0.73.tar.gz安装包 2.通过WinSCP传到linux下(本次放 ...
- 重写TreeView模板来实现数据分层展示(二)
前面一片文章实现TreeView的基本的模板重写,那么照着这个思路,我们再来写一个稍稍复杂的TreeView ,其它的内容都和前面系列内容相似,还是和之前文章介绍的一样,首先看看做出的DEMO的最终样 ...
- Java多线程之静态代理
package org.study2.javabase.ThreadsDemo.staticproxy; /** * @Date:2018-09-18 静态代理 设计模式 * 1.真实角色 * 2.代 ...
- LODOP暂存、应用、复原 按钮的区别
LODOP中打印设计(PRINT_DESIGN)有暂存和复原按钮,打印维护(PRINT_SETUP)有应用和复原按钮. 打印设计暂存和打印维护的应用功能不同,两者的区别:1.打印设计的暂存.复原(类似 ...
- 启动docker容器 防火墙问题报错 ! -i docker0' failed: iptables: No chain/target/match by that name.
COMMAND_FAILED: '/sbin/iptables -t nat -A DOCKER -p tcp -d 0/0 --dport 8111 -j DNAT --to-destination ...
- Opencv画图操作
1. 画矩形 MyRect rect;rect.left = 5;rect.top = 5;rect.right = 100;rect.bottom = 100;IplImage * pColorIm ...
- July 算法习题 - 字符串4(全排列和全组合)
https://segmentfault.com/a/1190000002710424 思想:当前层各节点首元素不同,则各节点的剩余元素也不同:下一层节点交换范围为首元素以外的元素 全排列算法: vo ...