본 내용은 파이썬 알고리즘 문제풀이 (코딩테스트 대비) 강의를 토대로 작성하였습니다.

# 숫자만 추출
import sys
#sys.stdin=open("input.txt", "r")
word = input()
res = ""
num = 0
# 숫자 추출
for i in word:
if i.isdigit():
res += i
res =int(res);
# 약수 추출
for i in range(1, res+1):
if res % i == 0 :
num += 1
print(res)
print(num)
이전 강의에서 배운 부분을 활용한 강사님 코드
# 숫자만 추출
import sys
sys.stdin=open("input.txt", "r")
s=input()
res=0
for x in s:
# isdecimal : 0~9까지의 숫자만
if x.isdecimal():
# 숫자로 변환
res=res*10+int(x)
print(res)
cnt=0
for i in range(1, res+1):
if res%i==0:
cnt+=1
print(cnt)
'Algorithm > 파이썬 알고리즘 문제풀이' 카테고리의 다른 글
[python/inflearn/section3] 두 리스트 합치기 (0) | 2022.09.22 |
---|---|
[python/inflearn/section3] 카드 역배치(정올 기출) (0) | 2022.09.22 |
[python/inflearn/section3] 회문 문자열 검사 (0) | 2022.09.22 |
[python/inflearn/section2] 점수계산 (0) | 2022.09.18 |
[python/inflearn/section2] 주사위게임 (0) | 2022.09.18 |