[백준/파이썬] 14761번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 14761번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
According to Wikipedia, FizzBuzz is a group word game for children to teach them about division. This may or may not be true, but this question is generally used to torture screen young computer science graduates during programming interviews.
Basically, this is how it works: you print the integers from 1 to N, replacing any of them divisible by X with Fizz or, if they are divisible by Y , with Buzz. If the number is divisible by both X and Y , you print FizzBuzz instead.
Check the samples for further clarification.
입력 요약
Input file will contain a single test case. Each test case will contain three integers on a single line, X, Y and N (1 ≤ X < Y ≤ N ≤ 100).
출력 요약
Print integers from 1 to N in order, each on its own line, replacing the ones divisible by X with Fizz, the ones divisible by Y with Buzz and ones divisible by both X and Y with FizzBuzz.
코드
x,y,n=map(int,input().split())
for i in range(1,n+1):
if i%x==0==i%y:print('FizzBuzz')
elif i%x==0:print('Fizz')
elif i%y==0:print('Buzz')
else:print(i)
설명
핵심은 구현 관점에서 According to Wikipedia, FizzBuzz is a group word game for children to teach them about division. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기