题目
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.
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
题意
计算学生的课程最终成绩并排序打印通过课程的学生分数名单,公式为:最终成绩=期中*0.4+期末*0.6。如果期末比期中高就不采用期中成绩,而且线上编程分数不低于200分。
难点
1.这道题的难点就是给的规则很多,每条都要仔细地过,漏了就有问题:
比如编程分数不低于两百,最终成绩的算法等等
2.map和unordered_map都能用,保险起见一律unordered_map
3.人名与编号的转换问题
如果人名aaa对应0号,那就得小心,比如:
map<string,int> m;//人名->编号
m["aaa"]为0,但是第一次出现的人名zzz,m["zzz"]也为0。
这里有个2分的测试点,对策就是在条件语句里加个判断就行了。
liuchuo的代码有另一种处理的方式,也很简单:https://blog.youkuaiyun.com/liuchuo/article/details/79064895?utm_source=blogxgwz6
满分代码
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int n,m,j,k,num=0;
string sn;
struct node{
string id;
int gp,gm,gf,g;
};
bool cmp(node &a,node &b){
return a.g!=b.g?a.g>b.g:a.id<b.id;
}
int main(){
scanf("%d %d %d",&n,&j,&k);
vector<node> v;
unordered_map<string,int> m1;
for(int i=0;i<n;i++){
cin>>sn>>m;
if(m>=200){
m1[sn]=num;
v.push_back({sn,m,-1,-1,0});
num++;
}
}
for(int i=1;i<=j;i++){
cin>>sn>>m;
if(m1[sn]!=0 || v[0].id==sn) v[m1[sn]].gm=m;
}
for(int i=1;i<=k;i++){
cin>>sn>>m;
if(m1[sn]!=0 || v[0].id==sn) v[m1[sn]].gf=m;
}
for(int i=0;i<v.size();i++){
v[i].g=(v[i].gm>v[i].gf)? (int)floor(v[i].gf*0.6+v[i].gm*0.4+0.5):v[i].gf;
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<v.size();i++){
if(v[i].g>=60)printf("%s %d %d %d %d\n",v[i].id.c_str(),v[i].gp,v[i].gm,v[i].gf,v[i].g);
}
return 0;
}
该博客介绍了PAT甲级编程竞赛中的1137题,涉及在线课程“数据结构”的证书资格计算。学生需在编程任务中得分超过200分,并根据期中和期末考试成绩计算最终成绩。文章讨论了题目的输入输出规格、难点,包括分数阈值、成绩计算规则和排序要求,并提醒注意处理人名与编号映射的特殊情况。
1481

被折叠的 条评论
为什么被折叠?



