1137 Final Grading (25 point(s))

1137 Final Grading (25 point(s))

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%+G​final​​×60%) if G​mid−term​​>G​final​​, or G​final​​ will be taken as the final grade G. Here G​mid−term​​ and G​final​​ 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 G​p​​'s; the second one contains M mid-term scores G​mid−term​​'s; and the last one contains N final exam scores G​final​​'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 G​p​​ G​mid−term​​ G​final​​ 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

排序、STL(unordered_map、vector)。

写完这个题,真的想打自己两耳光。认真读题真的不是一句开玩笑的话!这里是说在线成绩大于200分且总评成绩大于60分才可以获得证书,而不是期末卷面成绩要大于60分!注意final grade和final exam grade!做的时候还在想ZJU期末卷面及格才可以真正及格很严厉,哈哈原来也不是的。

注意点:

1. 最开始是思路是存储在数组里,然后建立姓名到编号(自定义)的映射,然后下标对于编号的数组元素存储结构体。实际上可以直接建立map<string,grade> mp的映射,然后采取pair的方式或者再把map的key存储到value中,然后提取到线性结构vector中排序;

2. 注意C++11 auto的使用,极大减少代码量;

3. 取整函数round(),也可直接加0.5。

代码1:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<cmath>
using namespace std;
struct grade{
	string id;int online=-1,mid=-1,final=-1;int total=0;
	void calculator(){
		if(mid>final) total=(int)(0.5+mid*0.4+final*0.6);
		else total=final;
	}
};
bool cmp(grade a,grade b){
	if(a.total!=b.total) return a.total>b.total;
	else return a.id<b.id;
}
unordered_map<string,grade> mp; 
vector<grade> v;
int P,M,N;
int main(void){
	cin>>P>>M>>N;//ONLINE MID FINAL
	string s;int n;
	for(int i=0;i<P;i++){
		cin>>s>>n;
		if(n<=900) mp[s].online = n;
	}
	for(int i=0;i<M;i++){
		cin>>s>>n;
		if(n<=100) mp[s].mid = n;
	}
	for(int i=0;i<N;i++){
		cin>>s>>n;
		if(n<=100) mp[s].final = n;
	}
	for(auto it:mp){
		if((it.second).online>=200){
			(it.second).calculator();
			if((it.second).total>=60){
				(it.second).id = it.first;
				v.push_back(it.second);
			}
			
		}
	}
	sort(v.begin(),v.end(),cmp);
	for(int i=0;i<v.size();i++){
		cout<<v[i].id<<" "<<v[i].online<<" "<<v[i].mid<<" "<<v[i].final<<" "<<v[i].total<<endl;
	} 
	return 0; 
}

代码2: 

#include<iostream>
#include<cstring>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<cmath>
using namespace std;
const int MAX = 3e4+7;
struct grade{
	string id;int online=-1,mid=-1,final=-1;int total=0;
	void calculator(){
		if(mid>final) total=(int)round(0.40*(double)mid+0.60*(double)final);
		else total=final;
	}
	bool operator < (const grade &other) const{
		if(total!=other.total) return total>other.total;
		return id<other.id;
	}
};
unordered_map<string,int> mp;//name-index 
grade G[MAX];
vector<grade> v;
int main(void){
	int P,M,N;cin>>P>>M>>N;//ONLINE MID FINAL
	int index = 0;string s;int n;
	mp.clear();
	for(int i=0;i<P;i++){
		cin>>s>>n;
		if(mp.find(s)!=mp.end()){
			G[mp[s]].online=n;
		}else{
			mp.insert({s,index});
			index++;
			G[mp[s]].online=n;
			G[mp[s]].id=s;
		}
	}
	for(int i=0;i<M;i++){
		cin>>s>>n;
		if(mp.find(s)!=mp.end()){
			G[mp[s]].mid=n;
		}else{
			mp.insert({s,index});
			index++;
			G[mp[s]].mid=n;
			G[mp[s]].id=s;
		}
	}
	for(int i=0;i<N;i++){
		cin>>s>>n;
		if(mp.find(s)!=mp.end()){
			G[mp[s]].final=n;
		}else{
			mp.insert({s,index});
			index++;
			G[mp[s]].final=n;
			G[mp[s]].id=s;
		}
	}
	for(int i=0;i<index;i++){
		G[i].calculator();
		if(G[i].online>=200&&G[i].total>=60){
			v.push_back(G[i]);
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++) cout<<v[i].id<<" "<<v[i].online<<" "<<v[i].mid<<" "<<v[i].final<<" "<<v[i].total<<endl;
	return 0; 
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值