其他分享
首页 > 其他分享> > 【PAT刷题甲级】1137.Final Grading

【PAT刷题甲级】1137.Final Grading

作者:互联网

1137 Final Grading (25 分)

针对测试点3答案错误,已解决!
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=(G
mid−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

题意

计算学生各项成绩,只有机试成绩>=200且最终成绩即总成绩(注意不是期末考试成绩)>=60 && <=100才有资格列入名单。
若期中成绩>期末成绩,总成绩 = 期中 * 0.4 + 期末 * 0.6
否则,总成绩=期末成绩
测试点3错误原因:
(1)注意是总成绩不是期末考试成绩>=60 && <=100有资格列入名单
(2)期中考试得0分与缺考者均显示0分,这里用tested标记参加考试的人
(3)用map标记考生id时,若从0开始标记,会与不存在的情况混淆,所以需要从1开始记录。

代码

#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
using namespace std;
struct node {
	string id;
	int gp,gm,gf,g;
} stu[10000];
map<string,int> book;
bool exist[10000],tested[10000]; //tested记录参加期中考试的人,避免考试得0分的人与缺考的人混淆
vector<node> v;
bool cmp(node a,node b) {
	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);
	string s;
	int t;
	for(int i=1; i<=p; i++) {   //由于map自动保存值为0,为避免与不存在混淆,i从1开始遍历
		cin >> s >> t;
		if(t>=200) {
			book[s]=i;
			exist[i]=true;
			stu[i].id=s;
			stu[i].gp=t;
		}
	}
	for(int i=0; i<m; i++) {
		cin >> s >> t;
		if(exist[book[s]]==true) {
			stu[book[s]].gm=t;
			tested[book[s]]=true;
		}
	}
	for(int i=0; i<n; i++) {
		cin >> s >> t;
		if(exist[book[s]]==true) {
			stu[book[s]].gf=t;
		}
	}
	for(int i=1; i<=p; i++) {
		if(exist[i]==true) {
			if(stu[i].gm>stu[i].gf)
				stu[i].g=round(stu[i].gm*0.4+stu[i].gf*0.6);
			else
				stu[i].g=stu[i].gf;
			if(tested[i]==false)	stu[i].gm=-1;
			if(stu[i].g>=60 && stu[i].g<=100)
				v.push_back(stu[i]);
		}
	}
	sort(v.begin(),v.end(),cmp);
	for(int i=0; i<v.size(); i++) {
		printf("%s %d %d %d %d\n",v[i].id.c_str(),v[i].gp,v[i].gm,v[i].gf,v[i].g);
	}
}

标签:term,gf,PAT,Grading,int,1137,stu,book,final
来源: https://blog.csdn.net/C_greenbird/article/details/120367011