当前位置 : 主页 > 网页制作 > HTTP/TCP >

PAT甲级——A1137 Final Grading【25】

来源:互联网 收集:自由互联 发布时间:2021-06-16
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

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 0 if G?midterm??>G?final??, or G?final?? will be taken as the final grade G. Here G?midterm?? 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?midterm??‘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?midterm?? G?final?? G

If some score does not exist, output "−" 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
 1 #include <iostream>
 2 #include <vector>
 3 #include <unordered_map>
 4 #include <string>
 5 #include <algorithm>
 6 #include <cmath>
 7 using namespace std;
 8 struct Node
 9 {
10     string name;
11     int Gp = -1, Gmid = -1, Gfinal = -1, G;//之所以不给-1,方便后面相加不用判断
12 };
13 int p, m, n;
14 unordered_map<string, int>nameID;
15 vector<Node>students;
16 int main()
17 {
18     int score;
19     string name;
20     cin >> p >> m >> n;
21     while (p--)
22     {
23         cin >> name >> score;
24         if (score < 200)//小于200的不要
25             continue;
26         nameID[name] = students.size();
27         students.push_back(Node{ name,score,-1,-1,0 });
28     }
29     while (m--)
30     {
31         cin >> name >> score;
32         if (nameID.find(name) != nameID.end())//无记录的不要            
33             students[nameID[name]].Gmid = score;
34     }
35     while (n--)
36     {
37         cin >> name >> score;
38         if (nameID.find(name) != nameID.end())//无记录的不要            
39             students[nameID[name]].Gfinal = score;
40     }
41     for (int i = 0; i < students.size(); ++i)
42     {
43         if (students[i].Gfinal > students[i].Gmid)
44             students[i].G = students[i].Gfinal;
45         else
46             students[i].G = round(students[i].Gmid*0.4 + students[i].Gfinal*0.6);
47     }
48     sort(students.begin(), students.end(), [](Node a, Node b)
49     {
50         if (a.G == b.G)
51             return a.name < b.name;
52         else
53             return a.G > b.G;
54     });
55     for (auto v : students)
56         if (v.Gp >= 200 && v.G >= 60)
57             cout << v.name << " " << v.Gp << " " << v.Gmid << " " << v.Gfinal << " " << v.G << endl;
58     return 0;
59 }
网友评论