PAT B1080 MOOC on the final score (25 points)

Topic links : https://pintia.cn/problem-sets/994805260223102976/problems/994805261493977088

Title Description
for student learning curriculum "data structure" in Chinese University MOOC (http://www.icourse163.org/), you want to get a certificate, you must first obtain not less than 200 points of online programming job points, Overall then obtained less than 60 (out of 100). Overall score is calculated as G = (G mid-term × 40% + G final × 60%), if G mid-term> G final; otherwise Overall G is G final. Here G mid-term and G final were students of midterm and final grades.

The problem now is that every test produced an independent report card. This question will ask you to write a program, put together as a different report card.

Enter the
input given three integers in the first line, namely P (the number of jobs to do online programming student), (the number of students participated in the midterm) M, N (to participate in the final examination of the number of students). Each number no more than 10,000.

Then there are three inputs. A first score line programming of P G p; second block includes M midterm scores G mid-term; third block contains N final examination G final. Each performance per line, in the format: school student scores. Wherein the student number is no more than 20 characters in English letters and numbers; non-negative integer fraction (maximum 900 points out the programming, the end of the period, and the highest score of 100 points).

Output
print out the list of students who obtain a certificate of competency. Each student per line, in the format:

Student number G p G mid-term G final G

If some results (for example, a person did not participate in the mid-term exam), the corresponding position "-1" does not exist. Overall output in accordance with descending order of scores (rounded to the nearest integer). If tied, press student number is incremented. Topic ensure there is no duplication student number, and there is at least one qualified students.

样例输入
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 98 82 88 200 is
dx86w 220 88 81 84
wehu8 300 55 84 84

Code

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;


struct student{
	string id;
	int G_p, G_m, G_f, G;
	student() {								//用构造函数赋初值
		G_p = -1; G_m = -1; G_f = -1;
	}
}stu[100010], s[100010];

bool cmp(student a, student b) {
	if(a.G != b.G)
		return a.G > b.G;
	else
		return a.id < b.id;
}

int main() {
	int p, m, n, temp, count = 0, num = 1;
	string name;
	map<string, int> mp;					//用mp来对学号进行编号
	cin >> p >> m >> n;
	for(int i = 0; i < p + n + m; i++) {
		cin >> name >> temp;
		if(mp[name] == 0) {					//若此学号第一次输入		
			mp[name] = num;
			stu[num].id = name;
			num++;
		}
		if(i < p)
			stu[mp[name]].G_p = temp;
		else if(i < p + m)
			stu[mp[name]].G_m = temp;
		else
			stu[mp[name]].G_f = temp;
	}
	for(int i = 1; i <= num; i++) {
		if(stu[i].G_m > stu[i].G_f)
			stu[i].G = (int)((stu[i].G_m * 1.0 * 0.4 +  stu[i].G_f * 1.0 * 0.6) + 0.5);
		else
			stu[i].G = stu[i].G_f;
		if(stu[i].G_p >= 200 && stu[i].G >= 60)			//合格
			s[count++] = stu[i];
	}
	sort(s, s + count, cmp);
	for(int i = 0; i < count; i++)
		cout << s[i].id << ' ' << s[i].G_p << ' ' << s[i].G_m << ' ' << s[i].G_f << ' ' << s[i].G << endl;
	return 0;
}
Published 327 original articles · won praise 12 · views 20000 +

Guess you like

Origin blog.csdn.net/Rhao999/article/details/105207702