回答編集履歴

4

リファクタ

2018/04/27 17:37

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -28,15 +28,15 @@
28
28
 
29
29
  standard_hour = (base_hour - timezone_table[base_city]) % 24
30
30
 
31
- for city, diff in timezone_table.items():
31
+ for diff in timezone_table.values():
32
32
 
33
- print(f'{(standard_hour + timezone_table[city]) % 24:02d}:{base_minute:02d}')
33
+ print(f'{(standard_hour + diff) % 24:02d}:{base_minute:02d}')
34
34
 
35
35
  ```
36
36
 
37
37
 
38
38
 
39
- [Wandbox](https://wandbox.org/permlink/Jw06bs2RkidFyqjd)
39
+ [Wandbox](https://wandbox.org/permlink/fvC7likOXLyuWNpt)
40
40
 
41
41
 
42
42
 

3

リファクタ

2018/04/27 17:37

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -20,23 +20,23 @@
20
20
 
21
21
 
22
22
 
23
- base_city, time = input().split()
23
+ base_city, base_time = input().split()
24
24
 
25
- hour, minute = map(int, time.split(':'))
25
+ base_hour, base_minute = map(int, base_time.split(':'))
26
26
 
27
27
 
28
28
 
29
- base_hour = (hour - timezone_table[base_city]) % 24
29
+ standard_hour = (base_hour - timezone_table[base_city]) % 24
30
30
 
31
31
  for city, diff in timezone_table.items():
32
32
 
33
- print(f'{(base_hour + timezone_table[city]) % 24:02d}:{minute:02d}')
33
+ print(f'{(standard_hour + timezone_table[city]) % 24:02d}:{base_minute:02d}')
34
34
 
35
35
  ```
36
36
 
37
37
 
38
38
 
39
- [Wandbox](https://wandbox.org/permlink/cWRKNntgSABzUL7q)
39
+ [Wandbox](https://wandbox.org/permlink/Jw06bs2RkidFyqjd)
40
40
 
41
41
 
42
42
 

2

追記

2018/04/27 17:35

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -42,4 +42,44 @@
42
42
 
43
43
  ---
44
44
 
45
- ややもすれば[datetimeモジュール](https://docs.python.jp/3/library/datetime.html)を使った方が簡単かしれません
45
+ [datetimeモジュール](https://docs.python.jp/3/library/datetime.html)を使ってみ例。どっちどっちですね
46
+
47
+ ```Python
48
+
49
+ from collections import OrderedDict
50
+
51
+ from datetime import datetime, timedelta
52
+
53
+
54
+
55
+ n = int(input())
56
+
57
+
58
+
59
+ timezone_table = OrderedDict()
60
+
61
+ for _ in range(n):
62
+
63
+ city, diff = input().split()
64
+
65
+ timezone_table[city] = timedelta(hours=int(diff))
66
+
67
+
68
+
69
+ base_city, base_time = input().split()
70
+
71
+ base_time = datetime.strptime(base_time, '%H:%M')
72
+
73
+
74
+
75
+ standard_time = (base_time - timezone_table[base_city])
76
+
77
+ for diff in timezone_table.values():
78
+
79
+ print(datetime.strftime(standard_time + diff, '%H:%M'))
80
+
81
+ ```
82
+
83
+
84
+
85
+ [Wandbox](https://wandbox.org/permlink/9A2bnhuRXjccu6M0)

1

修正

2018/04/27 14:18

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -1,4 +1,4 @@
1
- ちょっとだけ効率化できた...かも。あんまり変わってないようにも見えます。
1
+ ちょっとだけスマートにできた...かも。あんまり変わってないようにも見えます。
2
2
 
3
3
  ```Python
4
4