알고리즘/백준(BOJ)
[백준/BOJ/알고리즘/파이썬(python)]#8595_히든 넘버[문자열]
숲호랑이
2021. 9. 17. 18:57
https://www.acmicpc.net/problem/8595
8595번: 히든 넘버
첫째 줄에 단어의 길이 n (1 ≤ n ≤ 5,000,000)이 주어진다. 둘째 줄에는 단어가 주어진다. 단어는 알파벳 대/소문자와 숫자(0-9)로 이루어져 있다.
www.acmicpc.net
파이썬 코드
#8595 히든넘버
import sys
input = sys.stdin.readline
n = int(input())
st = input()
number = '0123456789'
hid = ''
for i in range(n):
if st[i] in number:
hid += st[i]
else:
hid += ' '
res = 0
hidfind = list(map(str, hid.split(' ')))
for i in hidfind:
if i != '':
res += int(i)
print(res)
숫자면 추가하고 그 외 문자면 공백으로
string으로 받아서 list로 map split하면 간편하게 숫자만 남는다.
문자열 활용을 센스껏 잘 해야하는 문제..