teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

4

リファクタ

2018/04/27 17:37

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -13,11 +13,11 @@
13
13
  base_hour, base_minute = map(int, base_time.split(':'))
14
14
 
15
15
  standard_hour = (base_hour - timezone_table[base_city]) % 24
16
- for city, diff in timezone_table.items():
16
+ for diff in timezone_table.values():
17
- print(f'{(standard_hour + timezone_table[city]) % 24:02d}:{base_minute:02d}')
17
+ print(f'{(standard_hour + diff) % 24:02d}:{base_minute:02d}')
18
18
  ```
19
19
 
20
- [Wandbox](https://wandbox.org/permlink/Jw06bs2RkidFyqjd)
20
+ [Wandbox](https://wandbox.org/permlink/fvC7likOXLyuWNpt)
21
21
 
22
22
  ---
23
23
  [datetimeモジュール](https://docs.python.jp/3/library/datetime.html)を使ってみた例。どっちもどっちですね。

3

リファクタ

2018/04/27 17:37

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -9,15 +9,15 @@
9
9
  city, diff = input().split()
10
10
  timezone_table[city] = int(diff)
11
11
 
12
- base_city, time = input().split()
12
+ base_city, base_time = input().split()
13
- hour, minute = map(int, time.split(':'))
13
+ base_hour, base_minute = map(int, base_time.split(':'))
14
14
 
15
- base_hour = (hour - timezone_table[base_city]) % 24
15
+ standard_hour = (base_hour - timezone_table[base_city]) % 24
16
16
  for city, diff in timezone_table.items():
17
- print(f'{(base_hour + timezone_table[city]) % 24:02d}:{minute:02d}')
17
+ print(f'{(standard_hour + timezone_table[city]) % 24:02d}:{base_minute:02d}')
18
18
  ```
19
19
 
20
- [Wandbox](https://wandbox.org/permlink/cWRKNntgSABzUL7q)
20
+ [Wandbox](https://wandbox.org/permlink/Jw06bs2RkidFyqjd)
21
21
 
22
22
  ---
23
23
  [datetimeモジュール](https://docs.python.jp/3/library/datetime.html)を使ってみた例。どっちもどっちですね。

2

追記

2018/04/27 17:35

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -20,4 +20,24 @@
20
20
  [Wandbox](https://wandbox.org/permlink/cWRKNntgSABzUL7q)
21
21
 
22
22
  ---
23
- ややもすれば[datetimeモジュール](https://docs.python.jp/3/library/datetime.html)を使った方が簡単かしれません
23
+ [datetimeモジュール](https://docs.python.jp/3/library/datetime.html)を使ってみ例。どっちどっちですね
24
+ ```Python
25
+ from collections import OrderedDict
26
+ from datetime import datetime, timedelta
27
+
28
+ n = int(input())
29
+
30
+ timezone_table = OrderedDict()
31
+ for _ in range(n):
32
+ city, diff = input().split()
33
+ timezone_table[city] = timedelta(hours=int(diff))
34
+
35
+ base_city, base_time = input().split()
36
+ base_time = datetime.strptime(base_time, '%H:%M')
37
+
38
+ standard_time = (base_time - timezone_table[base_city])
39
+ for diff in timezone_table.values():
40
+ print(datetime.strftime(standard_time + diff, '%H:%M'))
41
+ ```
42
+
43
+ [Wandbox](https://wandbox.org/permlink/9A2bnhuRXjccu6M0)

1

修正

2018/04/27 14:18

投稿

LouiS0616
LouiS0616

スコア35678

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