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 if , or will be taken as the final grade G. Here and 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
’s; the second one contains M mid-term scores
’s; and the last one contains N final exam scores
’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
$$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
Ω
分三块给出 上机、期中和期末 成绩名单,一个学生的最终成绩 计算方式如下:
期末成绩≥期中成绩:取期末成绩为总成绩
期末成绩<期中成绩:
如果上机分数没有到200分(包括没参加),或者总成绩G没到60分,则认定该学生成绩无效
那么最终需要输出所有成绩有效学生的各门分数+总成绩,按照总成绩降序排列,总成绩相同则按照ID升序排列。
我们先用一个map<string,tuple<int,int,int>>
建立ID到三门成绩的映射,第一轮读入上机分数,如果成绩没到200就不存入。接着读入期中和期末成绩,这里我们只将上机分数有效的同学成绩录入(就是map中能找到ID的)。然后按照上述规则计算这些同学的总成绩,将总成绩也有效(G≥60)的学生ID和G存入一个vector<pair<int,string>>
,以便后续的sort。指定cmp函数后直接sort,然后按照顺序输出即可。
🐎
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<int, string> pis;
int main()
{
int p, m, n, s, f;
cin >> p >> m >> n;
string id;
map<string, tuple<int, int, int>> score;
vector<pair<int, string>> final;
for (int i = 0; i < p; ++i)
{
cin >> id >> s;
if (s >= 200) score[id] = make_tuple(s, -1, -1);
}
for (int i = 0; i < m; ++i)
{
cin >> id >> s;
auto it = score.end();
if ((it = score.find(id)) != score.end())
get<1>(it->second) = s;
}
for (int i = 0; i < n; ++i)
{
cin >> id >> s;
auto it = score.end();
if ((it = score.find(id)) != score.end())
get<2>(it->second) = s;
}
for (auto &t: score)
{
f = get<1>(t.second) > get<2>(t.second) ? round(0.4 * get<1>(t.second) + 0.6 * get<2>(t.second))
: get<2>(t.second);
if (f >= 60) final.emplace_back(f, t.first);
}
sort(final.begin(), final.end(),
[](pis &a, pis &b) { return a.first != b.first ? a.first > b.first : a.second < b.second; });
for (auto &t: final)
printf("%s %d %d %d %d\n", t.second.c_str(), get<0>(score[t.second]), get<1>(score[t.second]),
get<2>(score[t.second]), t.first);
}
这里我对期中、期末成绩的初始化是-1,主要为了最后输出的方便,至于在计算总成绩的时候,如果期末成绩为-1(没参加考试)根本不可能让总成绩达到60;如果期中没考,那么就会选择期末成绩为总成绩,因此-1对总成绩计算没有影响。