-
[백준] 1110 - 더하기 사이클 (python)Problem Solving/Python 2023. 7. 12. 10:41반응형
1110번: 더하기 사이클
0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,
www.acmicpc.net
포인트
문제에 적힌 것 처럼 구현만 하면 됩니다. 다만 진입 시점에 주어진 숫자와 사이클 돌리는 숫자가 한번은 같을 수 밖에 없기 때문에 do - while 문처럼 실행될 필요가 있는데 python에는 do-while 문이 없기 때문에 저같은 경우엔 is_first라는 flag 를 둬서 이 부분을 처리했습니다.
코드
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 charactersinit_number_str = input() init_number = int(init_number_str) count = 0 is_first = True number = init_number while is_first or number != init_number: is_first = False # 십의 자리 숫자 decimal_number = number // 10 # 일의 자리 숫자 digit_number = number % 10 new_number = decimal_number + digit_number number = (digit_number * 10) + (new_number % 10) count += 1 print(count) 반응형'Problem Solving > Python' 카테고리의 다른 글
[백준] 1158 - 요세푸스 문제 (python) (0) 2023.07.17 [백준] 1157 - 단어 공부 (python) (0) 2023.07.12 [백준] 1094 - 막대기 (재귀 풀이) (python) (0) 2023.07.11 [백준] 1085 - 직사각형에서 탈출 (python) (0) 2023.07.11 [백준] 1076 - 저항 (python) (0) 2023.07.10