문제) 백준 - 구현 - 더하기 사이클
https://www.acmicpc.net/problem/1110
1110번: 더하기 사이클
0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,
www.acmicpc.net
C++ 소스 코드)
This file contains 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 | |
def refactor(n): | |
a = n // 10 | |
b = n % 10 | |
c = (a + b) % 10 | |
return (b * 10) + c | |
N = int(input()) | |
Target = N | |
ans = 0 | |
while 1: | |
ans += 1 | |
N = refactor(N) | |
if Target == N: | |
break | |
print(ans) |
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 1956번 - 운동 (C++) 문제 및 풀이 (0) | 2022.01.05 |
---|---|
[백준] 17471번 - 게리맨더링 (파이썬) 문제 및 풀이 (0) | 2022.01.04 |
[백준] 2251번 - 물통 (C++) 문제 및 풀이 (0) | 2021.12.31 |
[백준] 2533번 - 사회망 서비스(SNS) (C++) 문제 및 풀이 (0) | 2021.12.30 |
[백준] 10826번 - 피보나치 수 4 (Python) 문제 및 풀이 (0) | 2021.12.30 |
댓글