728x90
반응형
문제 출처:https://www.acmicpc.net/problem/1110
1110번: 더하기 사이클
0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,
www.acmicpc.net
풀이:
a = b = int(input())
count =0
while True:
ten = a//10
one = a%10
total = ten + one
count += 1
a =int(str(a%10)+str(total%10))
if(a == b):
break
print(count)
while 문 안에
a =int(str(a%10)+str(total%10))
str 을 해준 이유는 str 로 형 변환후 1 + 2 는 3이 아닌 12 로 나오기때문이다.
반응형
댓글