回答編集履歴
4
修正
test
CHANGED
@@ -22,7 +22,9 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
+
2つ目のプログラムはmapの用法の悪い例です。
|
26
|
+
|
25
|
-
指示
|
27
|
+
今回の問題のポイントは、指示が上から下へと順序があるので、その通りに実行する必要があるため内包表記の処理に改めました。
|
26
28
|
|
27
29
|
|
28
30
|
|
3
追記
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
--- 追記 ---
|
13
|
+
--- 追記1 ---
|
14
14
|
|
15
15
|
|
16
16
|
|
@@ -18,6 +18,14 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
--- 追記2 ---
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
指示は上から下へと順序があるので、その通りに実行する必要があるためmapは不要だと私は結論付けました。
|
26
|
+
|
27
|
+
|
28
|
+
|
21
29
|
```python
|
22
30
|
|
23
31
|
'''
|
@@ -68,9 +76,13 @@
|
|
68
76
|
|
69
77
|
print(reduce(run_command, init_property + commands))
|
70
78
|
|
71
|
-
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
72
|
-
|
83
|
+
``` python
|
84
|
+
|
73
|
-
# —- Another solution —-
|
85
|
+
# —- Another solution 1 —-
|
74
86
|
|
75
87
|
|
76
88
|
|
@@ -155,3 +167,79 @@
|
|
155
167
|
print(status)
|
156
168
|
|
157
169
|
```
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
``` python
|
174
|
+
|
175
|
+
# —- Another solution 2 —-
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
class Status:
|
180
|
+
|
181
|
+
def __init__(self):
|
182
|
+
|
183
|
+
self.properties = [0, 0]
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
def __str__(self):
|
188
|
+
|
189
|
+
return ' '.join(map(str, self.properties))
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
def s_in(self, i, v):
|
194
|
+
|
195
|
+
self.properties[i - 1] = v
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
def s_add(self, v):
|
200
|
+
|
201
|
+
self.properties[1] = self.properties[0] + v
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
def s_sub(self, v):
|
206
|
+
|
207
|
+
self.s_add(-v)
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
def command(cmd):
|
212
|
+
|
213
|
+
kw = command[0]
|
214
|
+
|
215
|
+
args = list(map(int, command[1:]))
|
216
|
+
|
217
|
+
after = {
|
218
|
+
|
219
|
+
'IN': status.s_in,
|
220
|
+
|
221
|
+
'Add': status.s_add,
|
222
|
+
|
223
|
+
'Sub': status.s_sub,
|
224
|
+
|
225
|
+
}[kw](*args)
|
226
|
+
|
227
|
+
return None
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
status = Status()
|
232
|
+
|
233
|
+
commands = [
|
234
|
+
|
235
|
+
input().split()
|
236
|
+
|
237
|
+
for _ in range(int(input()))
|
238
|
+
|
239
|
+
]
|
240
|
+
|
241
|
+
after = [status.command(cmd) for cmd in commands]
|
242
|
+
|
243
|
+
print(status)
|
244
|
+
|
245
|
+
```
|
2
追記
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
|
17
|
+
LouiS0616さんのクラスのアイデアからmapを使用した別解を提案します。
|
18
18
|
|
19
19
|
|
20
20
|
|
1
追記
test
CHANGED
@@ -7,6 +7,14 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
run_commandはプレイヤーの財産(property)と指示(command)を引数に指示に従った後のプレイヤーの財産を返します。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
--- 追記 ---
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
10
18
|
|
11
19
|
|
12
20
|
|
@@ -60,4 +68,90 @@
|
|
60
68
|
|
61
69
|
print(reduce(run_command, init_property + commands))
|
62
70
|
|
71
|
+
|
72
|
+
|
73
|
+
# —- Another solution —-
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
class Status:
|
78
|
+
|
79
|
+
def __init__(self):
|
80
|
+
|
81
|
+
self.properties = [0, 0]
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def __str__(self):
|
86
|
+
|
87
|
+
return ' '.join(map(str, self.properties))
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def s_in(self, i, v):
|
92
|
+
|
93
|
+
self.properties[i - 1] = v
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
def s_add(self, v):
|
98
|
+
|
99
|
+
self.properties[1] = self.properties[0] + v
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
def s_sub(self, v):
|
104
|
+
|
105
|
+
self.s_add(-v)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
def run_command(status):
|
112
|
+
|
113
|
+
command_dict = {
|
114
|
+
|
115
|
+
'IN': status.s_in,
|
116
|
+
|
117
|
+
'Add': status.s_add,
|
118
|
+
|
119
|
+
'Sub': status.s_sub,
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def _run_command(command):
|
126
|
+
|
127
|
+
kw = command[0]
|
128
|
+
|
129
|
+
args = list(map(int, command[1:]))
|
130
|
+
|
131
|
+
command_dict[kw](*args)
|
132
|
+
|
133
|
+
return None
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
return _run_command
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
status = Status()
|
144
|
+
|
145
|
+
commands = [
|
146
|
+
|
147
|
+
input().split()
|
148
|
+
|
149
|
+
for _ in range(int(input()))
|
150
|
+
|
151
|
+
]
|
152
|
+
|
153
|
+
after = list(map(run_command(status), commands))
|
154
|
+
|
155
|
+
print(status)
|
156
|
+
|
63
157
|
```
|