Algorithm/BOJ
GPA - 17662
jhg0406
2020. 2. 28. 18:58
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
88
89
90
91
92
93
94
|
//17662 - GPA
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int C, M, S;
map<string, double> cunit;
vector<string> mname;
vector<vector<string>> mclass;
map<string, double> student;
double head;
double tail;
void init()
{
cout << fixed;
cout.precision(2);
head = tail = 0.0;
cin >> C >> M >> S;
string s;
double x;
mname = vector<string>(M);
mclass = vector<vector<string>>(M);
for(int i = 0; i<C; ++i)
{
cin >> s >> x;
cunit[s] = x;
}
for(int i = 0; i<M; ++i)
{
cin >> s >> x;
mname[i] = s;
for(int j = 0; j<(int)x; ++j)
{
cin >> s;
mclass[i].push_back(s);
}
}
}
void cal(int C)
{
head = tail = 0.0;
student.clear();
int num;
cin >> num;
string s;
double grade;
for(int i = 0; i<num; ++i)
{
cin >> s >> grade;
student[s] = grade;
head += cunit[s]*grade;
tail += cunit[s];
}
cout << "Student " << C << "\n";
cout << "GPA: " << head/tail << "\n";
for(int i = 0; i<M; ++i)
{
head = tail = 0.0;
bool flag = true;
for(int j = 0; j<mclass[i].size(); ++j)
if(student.count(mclass[i][j]) == 0)
{
flag = false;
break;
}
else
{
head += student[mclass[i][j]]*cunit[mclass[i][j]];
tail += cunit[mclass[i][j]];
}
if(flag)
cout << mname[i] << ": " << head/tail << "\n";
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int C; cin >> C;
for(int tn = 0; tn<C; ++tn)
{
cout << "Data Set " << tn+1 << ":\n";
init();
for(int i = 0; i<S; ++i)
cal(i+1);
cout << "\n";
}
}
|
cs |
GPA
자료구조 문제 입니다!