A1137 Final Grading (25 point(s))

map充当散列使用

1. 原文

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 G=(Gmid−term×40%+Gfinal×60%) if Gmid−term>Gfinal, or Gfinal will be taken as the final grade G. Here Gmid−term and Gfinal 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 Gp‘s; the second one contains M mid-term scores Gmidterm‘s; and the last one contains N final exam scores Gfinal‘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 Gp Gmidterm Gfinal G

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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:

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

2. 解析

Online midterm final 分别存于对应map中,每个输出值studentID存入set中,根据set值扫描studentID对应各个分数值。

分数值都+1 防止有的studentID的分数本就是0.

3. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
char str[30];
map<string,int> online,midterm,final;
set<string> student;
struct node{
string id;
int score[4];
};
vector<node> ans;
bool cmp(node a,node b){
if (a.score[3]!=b.score[3])
{
return a.score[3]>b.score[3];
}else{
return a.id<b.id;
}
}
int main()
{
int p,m,n;
scanf("%d%d%d",&p,&m,&n);
int score; string id;
for (int i = 0; i < p; ++i)
{
scanf("%s%d",str,&score);
id=str;
online[id]+=score+1;
student.insert(id);
}
for (int i = 0; i < m; ++i)
{
scanf("%s%d",str,&score);
id=str;
midterm[id]+=score+1;
student.insert(id);
}
for (int i = 0; i < n; ++i)
{
scanf("%s%d",str,&score);
id=str;
final[id]+=score+1;
student.insert(id);
}
for (set<string>::iterator i = student.begin(); i != student.end(); ++i)
{
int total=0;
node temp;
temp.id=*i;
temp.score[0]=online[*i];
temp.score[1]=midterm[*i];
temp.score[2]=final[*i];
if (midterm[*i]>final[*i])
{
total=round((midterm[*i]-1)*0.4+(final[*i]-1)*0.6)+1;
}else{
total=final[*i];
}
temp.score[3]=total;
if (online[*i]>=201&&total>=61&&total<=101)
{
ans.push_back(temp);
}
}
sort(ans.begin(), ans.end(),cmp);
for (int i = 0; i < ans.size(); ++i)
{
printf("%s", ans[i].id.c_str());
for (int j = 0; j < 4; ++j)
{
if (ans[i].score[j]==0)
{
printf(" -1");
}else{
printf(" %d",ans[i].score[j]-1);
}
}
printf("\n");
}
return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/02/A1137/
  • 发布时间: 2019-09-02 20:47
  • 更新时间: 2021-10-29 14:10
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!