[백준/파이썬] 14682번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 14682번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Suppose we have a number like 12. Let’s define shifting a number to mean adding a zero at the end. For example, if we shift that number once, we get the number 120. If we shift the number again we get the number 1200. We can shift the number as many times as we want.
In this problem you will be calculating a shifty sum, which is the sum of a number and the numbers we get by shifting. Specifically, you will be given the starting number N and a non-negative integer k. …
입력 요약
The first line of input contains the number N (1 ≤ N ≤ 10000). The second line of input contains k, the number of times to shift N (0 ≤ k ≤ 5).
출력 요약
Output the integer which is the shifty sum of N by k.
코드
n,k,s=int(input()),int(input()),0
for i in range(k+1):
s+=n
n*=10
print(s)
설명
핵심은 구현 관점에서 Suppose we have a number like 12. Let’s define shifting a number to mean adding a zero at the end. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기