[BOJ] 3107 IPv6 - Python
2021. 8. 2. 23:25ㆍProgramming/Problem Solving
728x90
https://www.acmicpc.net/problem/3107
3107번: IPv6
첫째 줄에 올바른 IPv6 주소가 주어진다. 이 주소는 최대 39글자이다. 또한, 주소는 숫자 0-9, 알파벳 소문자 a-f, 콜론 :으로만 이루어져 있다.
www.acmicpc.net
와..
몇번이나 제출했는지 모르겠다 ㅋㅋ
진짜 계속 틀리길래.. 질문답변 게시판을 봤다.
0001:0002:0003:0004:0005:0006:0007:0000 -> 1:2:3:4:5:6:7::
이렇게 바꿀 수 있다는걸 보고.. 하,.....
내 코드에서는 그 부분을 처리하고 있지 않아서.. 그냥 어거지로 맞추긴 했는데..
쓰읍.. 내생각엔 별로 안좋은문제같다.
li = [-1] * 39
li[4] = li[9] = li[14] = li[19] = li[24] = li[29] = li[34] = ":"
ind = 38
ipv6 = input()
sp = ipv6.split(":")
colonCnt = 0
if len(sp) > 8:
if sp[-1] == "" and sp[-2] == "":
sp.pop()
for i in range(7, -1, -1):
if len(sp) <= 7-i:
now = ""
else:
now = sp[i-8]
if now == "":
colonCnt += 1
if colonCnt == 1:
for k in range(8-len(sp)):
sp.insert(i-8, "")
colonCnt = -9
for j in range(1, 5):
if j > len(now):
li[ind] = "0"
else:
li[ind] = now[-j]
ind -=1
ind-=1
num = "".join(li)
print(num)
'Programming > Problem Solving' 카테고리의 다른 글
[BOJ] 2307 도로검문 - Python (0) | 2021.08.05 |
---|---|
[BOJ] 8972 미친 아두이노 - Python (0) | 2021.08.02 |
[Programmers] 정수 삼각형 (0) | 2021.07.29 |
[BOJ] 17471 게리맨더링 - Python (0) | 2021.07.29 |
[BOJ] 2461 대표선수 - Python (0) | 2021.07.26 |