본문 바로가기
python-algorithm

[백준] 4821

by 무적김두칠 2021. 1. 8.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
while True:
    n=int(sys.stdin.readline())
    if n==0: exit()
    ans=[0]*(n+1)
    tmp=list(sys.stdin.readline().split(","))
    tmp[-1]=tmp[-1].replace("\n","")
    cnt=0
    for i in range(len(tmp)):
        if '-' in tmp[i] :
            a,b=map(int,tmp[i].split('-'))
            if a<=b:
                if a <=n :
                    if b<=n:
                        for j in range(a,b+1):
                            ans[j]=1
                    else:
                        b=n
                        for j in range(a,b+1):
                            ans[j]=1
        else:
            if int(tmp[i])<=n: ans[int (tmp[i])]=1
    print(sum(ans))
cs

조건이 상당히 까다롭습니다
한 시어머니 500명?

반응형

'python-algorithm' 카테고리의 다른 글

[백준] 4999  (0) 2021.01.09
[백준] 4998  (0) 2021.01.08
[백준] 4740  (0) 2021.01.08
[백준] 4592  (0) 2021.01.08
[백준] 4470  (0) 2021.01.08

댓글