## 문제
BOJ 1110 더하기 사이클
## 풀이
3 -> 03, 각자리 합하면 3
주어진 오른쪽 자리 3 합한것의 오른쪽 3을 붙여서 33
26에서 2+6 = 8 새로운 수는 68, 6+8=14 새로운 수는 84
반복해서 4번만에 원래 수로 돌아온다. 그래서 26의 사이클의 길이는 4.
N의 사이클의 길이 구하기(0<=N<=99)
## 코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
input = sys.stdin.readline | |
N_tmp = input() | |
if int(N_tmp) < 10: | |
N_tmp = '0' + N_tmp | |
N_input = N_tmp[:2] | |
count = 0 | |
while(True): | |
N_sum = int(N_tmp[0]) + int(N_tmp[1]) | |
N_tmp = N_tmp[1] + str(N_sum)[-1] | |
count += 1 | |
if(N_input == N_tmp): | |
break | |
print(str(count)) |
input 한 내용물에 \n이 들어가있지는 않은지, 10보다 작은 수가 들어가면 어떻게 해야 하는지 이런것만 따지면 어렵지 않았다.
0 댓글