๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿƒ algorithm/boj

BOJ 2231 - ๋ถ„ํ•ดํ•ฉ

by HandHand 2021. 6. 7.

๋ฌธ์ œ

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ - 2231๋ฒˆ

ํ’€์ด ๊ณผ์ •

์–ด๋–ค ๋ถ„ํ•ดํ•ฉ ๊ฒฐ๊ณผ๊ฐ€ ์ž์—ฐ์ˆ˜ N์ผ๋•Œ ์ด์— ๋Œ€ํ•œ ์ƒ์„ฑ์ž๋Š” N๋ณด๋‹ค ์ ˆ๋Œ€ ํด ์ˆ˜ ์—†๋‹ค๋Š” ์ ์„ ์ด์šฉํ•ด ๋ธŒ๋ฃจํŠธ ํฌ์Šค๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
์ด๋Š” ํ•œ ์ž์—ฐ์ˆ˜์™€ ๊ทธ ์ž๋ฆฟ์ˆ˜๋“ค์˜ ํ•ฉ์œผ๋กœ N์„ ๋งŒ๋“ค์–ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์ˆ˜๋ฅผ ํƒ์ƒ‰ํ•˜๋ฉด์„œ ๊ฐ€์žฅ ์ฒ˜์Œ ๋ฐœ๊ฒฌ๋˜๋Š” ์ƒ์„ฑ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys

N = int(input())


def separate_sum(N):
    temp = 0
    for c in str(N):
        temp += int(c)

    return N + temp


def solution():
    answer = 0
    for num in range(N):
        if N == separate_sum(num):
            answer = num
            break

    return answer


print(solution())
๋ฐ˜์‘ํ˜•

๐Ÿ’ฌ ๋Œ“๊ธ€