본문 바로가기

파이썬 알고리즘 (인프런)/탐색&시물레이션

2. 숫자만 추출

# 숫자만 추출

def run(s):
    # import re
    # a = re.findall("\d+", s)
    # n = int("".join(a))

    n = 0  # 숫자 추출
    for ch in s:
        if ch.isdecimal():
            n = n*10 + int(ch)

    cnt = 0  # 약수 개수
    for i in range(1, n+1):
        if n % i == 0:
            cnt += 1

    return n, cnt


s = input()
n, cnt = run(s)
print(n)
print(cnt)

'파이썬 알고리즘 (인프런) > 탐색&시물레이션' 카테고리의 다른 글

6. 격자판 최대합  (0) 2021.02.09
5. 수들의 합  (0) 2021.02.09
4. 두 리스트 합치기  (0) 2021.02.09
3. 카드 역배치  (0) 2021.02.09
1. 회문 문자열 검사  (0) 2021.02.09