ALGORITHM/PYTHON

백준 BAEKJOON 33709번 치매예방수칙 3.3.3 [PYTHON/파이썬]

칼코 2025. 4. 28. 17:27
728x90
반응형

 

 

 

 

 

백준 BAEKJOON 33709번 치매예방수칙 3.3.3 [PYTHON/파이썬]


[목차여기]

<문제 출처> (BRONZE Ⅰ)

https://www.acmicpc.net/problem/33709

 

 

 

 

 

 

 

<풀이>

슬로건의 구분자는 ., |, :, # 4가지이다.

replace를 사용하여 |, :, #. 으로 바꾸는 작업을 하여

split(".")을 사용하여 문자열을 구분해 준 뒤 숫자끼리 더해주었다.

 

 

 

 

 

 

<코드>

N = int(input())
slogan = input()
separator = ["|", ":", "#"]

for s in separator:
    slogan = slogan.replace(s, ".")

numberList = slogan.split(".")
result = 0

for n in numberList:
    result += int(n)

print(result)

 

 

 

 

 

 

 

 

728x90
반응형