[Algorithm/Python][백준] 2231번 분해합

동글이·2022년 8월 11일
0

Algorithm

목록 보기
16/33

[BOJ] 2231번 분해합

https://www.acmicpc.net/problem/2231

- 문제 접근

  • 얘도 브루트포스 알고리즘!(이정도로 노가다일 줄이야)
  • str를 이용해서 각각의 자리수를 간단하게 가져올 수 있음
  • sample=i+sum(map(int, str(i))) 를 이용하여 더 간단하게 계산 가능

- 처음 코드

N=int(input())

check=0
result=[]

for i in range(1,N):
    sum=i
    str_i=str(i)
    for j in range(len(str_i)):
        sum+=int(str_i[j])
    if N==sum:
        result.append(i)
        check=1
        break

if check==0:
    print(0)
else:
    print(min(result))

- 수정한 코드

N = int(input())
result = 0

for i in range(1, N+1):
    sample=i+sum(map(int, str(i)))
    if sample==N:
        result=i
        break

print(result)

✔ 한 일 점검


✔ 내일 목표

  • 백준 or 프로그래머스 - 2문제 이상
  • 스프링 - 실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발 끝내기
  • 파이썬 - 이코테 강의2
  • 창액 프로젝트 crud
  • 졸작 회의
  • 튜터링 면접..?
  • 운전면허 받으러 가기
  • 캐리비안 숙소 알아보기

✔ 주저리

profile
기죽지 않는 개발자

0개의 댓글