문제
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.
예제 입력 1
2 3 7 |
예제 출력 1
1 Fizz Buzz Fizz 5 FizzBuzz 7 |
예제 입력 2
2 4 7 |
예제 출력 2
1 Fizz 3 FizzBuzz 5 Fizz 7 |
예제 입력 3
3 5 7 |
예제 출력 3
1 2 Fizz 4 Buzz Fizz 7 |
Solution
#include<stdio.h>
int main(void)
{
int X, Y, N;
scanf("%d %d %d", &X, &Y, &N);
for(int n=1;n<=N;n++)
if(n%X==0 && n%Y==0)
printf("FizzBuzz\n");
else if(n%X==0)
printf("Fizz\n");
else if(n%Y==0)
printf("Buzz\n");
else
printf("%d\n", n);
return 0;
}
'백준 알고리즘' 카테고리의 다른 글
<백준 알고리즘> 7789번: 텔레프라임 (0) | 2021.01.03 |
---|---|
<백준 알고리즘> 16495번: 열 순서 (0) | 2021.01.03 |
<백준 알고리즘> 20499번: Darius님 한타 안 함? (0) | 2021.01.03 |
<백준 알고리즘> 11719번: 그대로 출력하기 2 (0) | 2021.01.02 |
<백준 알고리즘> 11729번: 하노이 탑 이동 순서 (0) | 2021.01.02 |