[백준] 1110. 더하기 사이클

원숭2·2022년 2월 8일
0

백준

목록 보기
32/54

문제

풀이

  1. 주어진 입력을 list로 변환 함.
  2. 문제의 조건대로 진행해주면서, 기존 n과 같아질 때 까지 while문을 돌며 같아질 시 return함.

코드

num = input()

def cycle(n) :
    count = 0
    std = n
    while 1 :
        n_list = list(n)
        if len(n_list) == 1 :
            n_list.insert(0, str(0))
        tmp = [n_list[1], str(int(n_list[0]) + int(n_list[1]))]
        count += 1
        if len(tmp[1]) > 1 and tmp[1] != '00' :
            tmp = [n_list[1], tmp[1][1]]
            n = ''.join(tmp)
        n = ''.join(tmp)
        if int(std) == int(n) :
            return count
print(cycle(num))

0개의 댓글