1080 MOOC final score (25 points)

subject

For MOOC in Chinese Universities( http://www.icourse163.org/ )Students studying the "data structure" course who want to obtain a qualification certificate must first obtain an online programming homework score of no less than 200 points, and then obtain a total score of no less than 60 points (out of 100). The calculation formula of the total score is G=(G − mid − term) × 40%+Gfinal × 60%), if G − mid − term > gfinal; Otherwise, the general comment G is gfinal. Here, Gmid − term and G − final are the students' midterm and final grades respectively.

The problem now is that each exam produces an independent report card. Please write a program to combine different transcripts into one.

Input format:

Input: three integers are given in the first line, which are P (the number of students who have done online programming homework), M (the number of students who have taken the midterm exam) and N (the number of students who have taken the final exam). Each number does not exceed 10000.

Next, there are three inputs. The first block contains P online programming scores G # p; The second block contains M mid-term test scores G − mid − term; The third block contains N final exam scores Gfinal. Each grade occupies one line in the form of student number score. The student number shall be English letters and numbers with no more than 20 characters; The score is a non negative integer (the maximum total score for programming is 900, and the maximum score at the end of the period is 100).

Output format:

Print out the list of students who have obtained the qualification certificate. One line for each student in the format:

Student ID: G p Gmid − term G final G
If some scores do not exist (for example, someone did not take the mid-term exam), output "− 1" in the corresponding position. The output order is decreasing according to the total evaluation score (rounded to the nearest integer). If there is juxtaposition, it will be increased by student number. Ensure that the student number is not repeated and there is at least one qualified student.

Input example:

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

Output example:

missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84

code

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
struct node{
	string name;
	int gp,gm,gf,g;
};
bool cmp(node a,node b){
	return a.g!=b.g?a.g>b.g:a.name<b.name; 
}
int main(){
	vector<node> stu,ans;
	map<string,int> idx;//Index the subscript in the vector of stu with the name string
	int p,m,n;
	string s;
	cin>>p>>m>>n;
	int score,k=1;
	for(int i=0;i<p;i++){
		cin>>s>>score;
		if(score>=200){
			stu.push_back(node{s,score,-1,-1,0});
			idx[s]=k++;//Record subscripts with programming scores greater than 200 
		}
	}
	for(int i=0;i<m;i++){
		cin>>s>>score;
		if(idx[s]!=0){
			stu[idx[s]-1].gm=score;
		}
	}
	for(int i=0;i<n;i++){
		cin>>s>>score;
		if(idx[s]!=0){
			stu[idx[s]-1].gf=score;
			stu[idx[s]-1].g=score;
			if(score<stu[idx[s]-1].gm)
				stu[idx[s]-1].g=int(0.4*stu[idx[s]-1].gm+0.6*score+0.5);
		}
	}
	for(int i=0;i<stu.size();i++){
		if(stu[i].g>=60)
			ans.push_back(stu[i]);
	}
	sort(ans.begin(),ans.end(),cmp);
	for(int i=0;i<ans.size();i++){
		printf("%s %d %d %d %d\n",ans[i].name.c_str(),ans[i].gp,ans[i].gm,ans[i].gf,ans[i].g);
	}
} 

summary

In c + +, fast scheduling can be realized through the self-contained sort (vector. Begin()), vector End, cmp), which is written in much the same way.
At the same time, map can be used to quickly index the corresponding value value through key. In this problem, first, a vector linear table is created to push_ Back (student grade node), and then idx this map stores the node subscripts of students who meet the programming scores of more than 200 points according to the student name. In the subsequent reading of the midterm and final grades, you can use the student name to take out the subscript from the idx map, and then index it in the vector to access the grade information.

Keywords: C++ Algorithm string Hash table

Added by ggkfc on Tue, 18 Jan 2022 08:54:23 +0200