Post

๐ŸฆŠ IPv6

1. ๋ฌธ์ œ ๋งํฌ

3107๋ฒˆ: IPv6


2. ์ฝ”๋“œ

Python3 31156KB 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
def get_full_string(string: str):
    return ("0" * max(0, 4 - len(string))) + string

base = ["0000"] * 8
short_string = input().split(":");

idx = 0
while short_string and idx < 8:
    begin = short_string.pop(0)
    if begin == "":
        break
    base[idx] = get_full_string(begin)
    idx += 1
    
idx = 7
while short_string and idx >= 0:
    end = short_string.pop()
    if end == "":
        break
    base[idx] = get_full_string(end)
    idx -= 1

print(':'.join(base))


3. ํ•ด์„ค

0000:0000 โ€ฆ. :0000 ์œผ๋กœ ๋ฐฐ์—ด ์ดˆ๊ธฐํ™”

split ํ–ˆ์„๋•Œ โ€œโ€ ๊ฐ™์ด ๋นˆ ๋ฌธ์ž์—ด์ด ๋‚˜์˜ค๋ฉด ์ด ๊ทธ๋ฃน์€ ์ƒ๋žต๋œ ๊ทธ๋ฃน์„ ํ‘œ์‹œ

์ด ๊ทธ๋ฃน์„ ๊ธฐ์ค€์œผ๋กœ ์•ž๋’ค๋กœ ์ž…๋ ฅ๊ฐ’์— 0 ์„ ๋ถ™์ธ 4์ž๋ฆฌ ๋ฌธ์ž์—ด์„ ๋ฐฐ์—ด์— ๋Œ€์ž…

๋งˆ์ง€๋ง‰์— โ€œ:โ€ ๋ถ™์—ฌ์„œ ์ถœ๋ ฅ

This post is licensed under CC BY 4.0 by the author.