1137 Final Grading (25 分)

版权声明:如有错误,请指出,不胜感激。 https://blog.csdn.net/qq_36424540/article/details/84192286

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

精度问题: 没有考虑四舍五入,那个地方。 

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

#define rep(i,a,b) for(int i=a;i<b;i++)

map<string,int> ID;

const double eps=1e-2;

const int N=20010;
struct Stu{
	string name;
	int a,b,c;
	double g;
	int sc;
	bool operator<(const Stu& b)const{
		if(sc==b.sc){
			return name<b.name;
		}else return sc>b.sc;
	}
	void show(){
		printf("*********\n");
		cout<<name<<" "<<a<<" "<<b<<" "<<c<<" "<<sc<<endl;		
	} 
}stu[N]; 

int cal(double x){
	x+=0.5;
	int t=x;
	//	printf("x:%.2f t:%d\n",t,x);
	return t;
}

int main(){
	
	rep(i,0,N)stu[i].a=stu[i].b=stu[i].c=-1;
	
	int n1,n2,n3;
	scanf("%d %d %d",&n1,&n2,&n3);
	
	int tot=0;
	string name;int sc;
	rep(i,0,n1){
		cin>>name>>sc;
		if(!ID[name]){
			ID[name]=++tot;
			stu[tot].name=name;
		//	cout<<"****"<<name<<endl;
		}
		int id=ID[name];
		stu[id].a=sc;
	}
	
	rep(i,0,n2){
		cin>>name>>sc;
		if(!ID[name]){
			ID[name]=++tot; 
			stu[tot].name=name;
			//cout<<"****"<<name<<endl;
		}		
		int id=ID[name];
		stu[id].b=sc;
	}
	
	rep(i,0,n3){
		cin>>name>>sc;
		if(!ID[name]){
			ID[name]=++tot; 
			stu[tot].name=name;
		}		
		int id=ID[name];
		stu[id].c=sc; 
	}	
	
	int cnt=0; 
	rep(i,1,tot+1){
		int id=i;
		if(stu[id].b!=-1&&stu[id].b>stu[id].c){
			stu[id].sc=int(stu[id].b*0.4+stu[id].c*0.6+0.5);
		}else{
			stu[id].sc=stu[id].c;
		}		
		//stu[id].sc=cal(stu[id].c);
		//printf("i:%d\n",i);
	//	stu[i].show();


                //!!!这里的判断写错了,应该是得分大于等于60。 得分就是四舍五入之后的,
                //我弄成没有四舍五入就 取值了。 所以当59.7的时候,我就会落下一些情况
		if(stu[id].a>=200&&stu[id].sc-60>=0){
			//printf("\n%.2f\n",stu[id].g);
		//	stu[id].sc=cal(stu[id].g);
		//	printf("****&&&\n");
			//stu[cnt].show();
			stu[cnt]=stu[id];
			//stu[cnt].show();
			cnt++;
		} 
	}
	
	//printf("***cnt:%d\n",cnt);
	sort(stu,stu+cnt);
	
	rep(i,0,cnt){
		rep(j,0,stu[i].name.length())putchar(stu[i].name[j]);
		printf(" %d %d %d %d\n",stu[i].a,stu[i].b,stu[i].c,stu[i].sc);
		//double g=stu[i].sc*1.0/10; 
	//	cout<<stu[i].name<<" "<<stu[i].a<<" "<<stu[i].b<<" "<<stu[i].c<<" "<<;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36424540/article/details/84192286