1137 Final Grading

#include<bits/stdc++.h>
using namespace std;
struct student{
	string id;
	int gp,gm,gf,g;
};
struct node{
	string id;
	int score;
};
bool cmp(student a,student b){
	if(a.g!=b.g){
		return a.g>b.g;
	}else{
		return a.id<b.id;
	}
}
int main(){
	#ifdef ONLINE_JUDGE
	#else
	freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
	#endif
	int p,m,n;
	cin>>p>>m>>n;
	set<string> stu1;
	vector<node> stu2,stu3,stu4;
	vector<student> st;
	for(int i=0;i<p;i++){
		string temp1;
		int temp2;
		cin>>temp1>>temp2;
		if(temp2>=200){
			node a;
			a.id=temp1;
			a.score=temp2;
			stu1.insert(temp1);
			stu2.push_back(a);
		}
	}
	for(int i=0;i<m;i++){
		string temp1;
		int temp2;
		cin>>temp1>>temp2;
		if(stu1.find(temp1)!=stu1.end()){
			node a;
			a.id=temp1;
			a.score=temp2;
			stu3.push_back(a);
		}
	}
	for(int i=0;i<n;i++){
		string temp1;
		int temp2;
		cin>>temp1>>temp2;
		if(stu1.find(temp1)!=stu1.end()){
			node a;
			a.id=temp1;
			a.score=temp2;
			stu4.push_back(a);
		}
	}
	for(set<string>::iterator it=stu1.begin();it!=stu1.end();it++){
		string idd;
		int gpp,gmm,gff,gg;
		student some_one;
		idd=*it;
		for(int j=0;j<stu2.size();j++){
			if(stu2[j].id==idd){
				gpp=stu2[j].score;
				break;
			}
		}
		int t;
		for(t=0;t<stu3.size();t++){
			if(stu3[t].id==idd){
				gmm=stu3[t].score;
				break;
			}
		}
		if(t==stu3.size()){
			gmm=-1;
		}
		for(int k=0;k<stu4.size();k++){
			if(stu4[k].id==idd){
				gff=stu4[k].score;
				break;
			}
		}
		if(((int)(gmm*0.4+gff*0.6+0.5)>=60)||gff>=60){
			some_one.id=idd;
			some_one.gp=gpp;
			some_one.gm=gmm;
			some_one.gf=gff;
			some_one.g=max((int)(gmm*0.4+gff*0.6+0.5),gff);
			st.push_back(some_one);
		}
	}
	sort(st.begin(),st.end(),cmp);
	for(int i=0;i<st.size();i++){
		cout<<st[i].id<<' '<<st[i].gp<<' '<<st[i].gm<<' '<<st[i].gf<<' '<<st[i].g<<endl;
	}
	return 0;
}

留作自己改进(最后一个测试点超时,第二个测试点未通过)

超时改进可以用map<string,int>代替stu1那个结构体,第二个测试点不通过修改g>60?

猜你喜欢

转载自blog.csdn.net/csg3140100993/article/details/81387680
今日推荐