공부/데이터사이언스
[백준] 3단계 - 1110번 (파이썬) check!
PYo
2022. 6. 20. 15:51
반응형
1110번
https://www.acmicpc.net/problem/1110
def func(x):
if x < 10:
a=0
b=x
else:
a=int(str(x)[0])
b=int(str(x)[1])
return a,b
n=0
x = int(input())
num=x
while ((n==0) or (x!=num)):
n += 1
a,b = func(num)
c,d = func(a+b)
num = int(str(b)+ str(d))
print(n)
뭔가 더 짧게 해보고 싶다... 방법 없나?ㅠㅠ
+ whiteeh님 코드 참고한 짧은 버전 코드 (추가)
n = 0
x = int(input())
new = x
while True:
a = new//10
b = new%10
new = b*10 + (a+b)%10
n += 1
if (new==x):
print(n)
break
반응형