๐ฃ IPv6
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
Python3
31120KB
40ms
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
import sys
input = sys.stdin.readline
address = input().rstrip()
origin = [[] for _ in range(8)]
sep_cnt = address.count(':')
idx = 0
for i in range(len(address)):
if address[i] == ':':
if i > 0 and address[i - 1] == ':': # ์ฐ์ ':' ๋ฑ์ฅ ์
while idx + sep_cnt < 8:
origin[idx] = ['0', '0', '0', '0'] # ์์ '0'์ผ๋ก ์ฑ์์ค
idx += 1
else:
while len(origin[idx]) < 4:
origin[idx].insert(0, '0') # ์์ '0'์ผ๋ก ์ฑ์์ค
idx += 1
sep_cnt -= 1
else:
origin[idx].append(address[i])
while len(origin[-1]) < 4:
origin[-1].insert(0, '0') # ์์ '0'์ผ๋ก ์ฑ์์ค
[print(''.join(origin[i]), ':', sep='', end='') for i in range(7)]
print(''.join(origin[-1]))
This post is licensed under CC BY 4.0 by the author.