[백준/파이썬] 16239번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 16239번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Alongside being a palindrome, Nadan is also a successful businessman who finances young software developers when they start working on their projects. This year, he decided to distribute K kunas (Croatian currency) to N projects in a way that each project gets at least one kuna and all projects get a different amounts of kunas. This will always be possible.
Write a program which will, for a given N and K, find one possible distribution of K kunas to N projects.
입력 요약
The first line contains a positive integer K (100 ≤ K ≤ 1 000 000), number from the task description. The second line contains a positive integer N (1 ≤ N ≤ 100), number from the task description.
출력 요약
For a chosen money distribution, output the amount of money the first project will get in the first line, the amount of money the second project will get in the second line and so on until the N-th line where you should output the amount of money the N-th project will get.
코드
k,n=int(input()),int(input())
for i in range(1,n):
print(i)
k-=i
print(k)
설명
핵심은 구현 관점에서 Alongside being a palindrome, Nadan is also a successful businessman who finances young software developers when they start working on their projects. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기