[PAT] grade B 1080 MOOC final score (25 points) c++

1080 MOOC final score (25 points)

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=(Gmid − term) × 40%+Gfinal × 60%), if Gmid − term > gfinal; Otherwise, the general comment G is gfinal. Here, Gmid − term and gfinal 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 Gp; The second block contains M midterm scores Gmid − 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: Gp Gmid − term Gfinal 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

Example code:

#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
struct node {
	string id;
	int gp;
	int gm;
	int gf;
	int g;
};
bool cmp(node n1, node n2) {
	if (n1.g != n2.g) {
		return n1.g > n2.g;
	}
	return n1.id < n2.id;
}
int main() {
	int P, M, N;
	string s;
	int score;
	int count = 1;
	cin >> P >> M >> N;
	map<string, int> idx;
	vector<node> v;
	vector<node> vf;
	for (int i = 0; i < P; i++) {
		cin >> s >> score;
		if (score >= 200 && score <= 900) {
			v.push_back(node{ s,score,-1,-1,0 });
			idx[s]=count++;
		}
	}
	for (int i = 0; i < M; i++) {
		cin >> s >> score;
		if (idx[s] !=0 && score >= 0 && score <= 100) {
			v[idx[s]-1].gm = score;
		}
	}
	for (int i = 0; i < N; i++) {
		cin >> s >> score;
		if (idx[s] != 0 && score >= 0 && score <= 100) {
			v[idx[s] - 1].gf = score;
			if (v[idx[s] - 1].gm >score) {
                v[idx[s] - 1].g = round(0.6*score + 0.4 * v[idx[s] - 1].gm);
				
			}
			else {
				v[idx[s] - 1].g = score;
			}
			if (v[idx[s] - 1].g >= 60) {
				vf.push_back(v[idx[s] - 1]);
			}
		}
	}
	sort(vf.begin(), vf.end(), cmp);
	for (auto i : vf) {
		cout << i.id << " " << i.gp << " " << i.gm << " " << i.gf << " " << i.g << endl;
	}

	return 0;
}

Keywords: C++

Added by why2k on Mon, 20 Sep 2021 13:54:54 +0300