回答編集履歴
1
追記
test
CHANGED
@@ -29,3 +29,137 @@
|
|
29
29
|
|
30
30
|
|
31
31
|
みたいな感じにしてやった方が読みやすいと思います。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
---
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
ファイル入出力を省略し標準入出力にて代替すると
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```c++
|
46
|
+
|
47
|
+
#include <iostream>
|
48
|
+
|
49
|
+
#include <fstream>
|
50
|
+
|
51
|
+
#include <string>
|
52
|
+
|
53
|
+
#include <sstream>
|
54
|
+
|
55
|
+
#include <vector>
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
using namespace std;
|
62
|
+
|
63
|
+
using P = pair<int,int>;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
class Student {
|
68
|
+
|
69
|
+
string name;
|
70
|
+
|
71
|
+
string code;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
vector<P> scores;
|
76
|
+
|
77
|
+
public:
|
78
|
+
|
79
|
+
Student(istream& fin);
|
80
|
+
|
81
|
+
void print(ostream& fout) const;
|
82
|
+
|
83
|
+
};
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
Student::Student(istream& fin){
|
88
|
+
|
89
|
+
string line;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
// name & code
|
94
|
+
|
95
|
+
getline(fin, line);
|
96
|
+
|
97
|
+
auto sep = line.rfind(" ");
|
98
|
+
|
99
|
+
name = line.substr(0, sep);
|
100
|
+
|
101
|
+
code = line.substr(sep+1);
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
// scores
|
106
|
+
|
107
|
+
for(getline(fin, line); !line.empty(); getline(fin, line)) {
|
108
|
+
|
109
|
+
istringstream ss(line);
|
110
|
+
|
111
|
+
int score, num;
|
112
|
+
|
113
|
+
ss >> score >> num;
|
114
|
+
|
115
|
+
scores.emplace_back(score, num);
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
};
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
void Student::print(ostream& fout) const {
|
124
|
+
|
125
|
+
fout << name << " " << code << " ";
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
long long total = 0;
|
130
|
+
|
131
|
+
double total_weight = 0;
|
132
|
+
|
133
|
+
for(const auto& [score, weight] : scores){
|
134
|
+
|
135
|
+
total += score * weight;
|
136
|
+
|
137
|
+
total_weight += weight;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
fout << total / total_weight << "\n";
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
int main(){
|
150
|
+
|
151
|
+
vector<Student> s;
|
152
|
+
|
153
|
+
while(cin){
|
154
|
+
|
155
|
+
s.emplace_back(cin);
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
for(const auto& p : s) p.print(cout);
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
```
|