지나가던 개발자

[Python] 백준 4821번(페이지 세기) 문제 풀이 본문

PS/Python

[Python] 백준 4821번(페이지 세기) 문제 풀이

KwonYongHyeon 2022. 11. 3. 18:03

 

while True:
    pages = [False for i in range(int(input()))]
    if len(pages) == 0:
        break
    toPrint = input().split(",")
    for i in toPrint:
        to_print = list(map(int, i.split("-")))
        if to_print[0] > len(pages):
            continue
        if len(to_print) == 1:
            pages[to_print[0]-1] = True
            continue
        if to_print[0] > to_print[1]:
            continue
        if to_print[1] > len(pages):
            to_print[1] = len(pages)
        for j in range(to_print[0], to_print[1]+1):
            pages[j-1] = True
    print(pages.count(True))

 

백준에 다크 모드를 적용해 보았다. 눈이 편안하다.

Comments