구현1 [python 백준 3107] IPv6 📜 접근 방법 1. ":"를 기준으로 문자열을 쪼갠다. 2. 쪼갠 문자열을 for문을 돌린다. 3. 빈 문자열일 경우 현재 문자열 갯수만큼 "0000:"을 추가한다. 4. 빈 문자열이 아닐 경우 (4 - s의 갯수)만큼 0을 추가한 후 문자열 s + : 를 추가한다. ❌ 실패 코드 import sys s_list = sys.stdin.readline().strip().split(":") res = "" check = True for s in s_list: if s == "": if check: if len(s_list) < 8: for i in range(8 - len(s_list)): res += "0000:" check = False res += "0000:" else: if len(s) != 4: .. 2023. 3. 13. 이전 1 다음