코드
n = int(input())
for i in range(1, n+1):
a = list(map(int, str(i)))
sum_sep = sum(a)
sum_all = i + sum_sep
if sum_all == n:
print(i)
break
if i == n:
print(0)
각각 분해합을 내주고, 자리수와 전체 숫자를 더해주는 방식으로 처리한 후, n과 같으면 이 값이 답
다시 한 번 자리수만 리스트로 만드는 방법 체크
for i in range(1, n+1):
a = list(map(int, str(i)))
sum_sep = sum(a)
sum_all = i + sum_sep
'코딩테스트 > Python' 카테고리의 다른 글
[이코테 강좌] Brute force 2번 시각 - python (0) | 2022.01.04 |
---|---|
[이코테 강좌] Brute force 1번 상하 좌우 - python (0) | 2022.01.04 |
[boj-백준] Brute force 1065 한수 - python (0) | 2022.01.04 |
[boj-백준] Brute force 4673 셀프 넘버 - python (0) | 2022.01.04 |
[boj-백준] Brute force 2309 일곱 난쟁이 - python (0) | 2022.01.04 |