#C9804. FizzBuzz Transformation
FizzBuzz Transformation
FizzBuzz Transformation
You are given a list of integers. Your task is to transform the list by applying the FizzBuzz rules:
- If a number is divisible by both 3 and 5, replace it with
FizzBuzz
. - If a number is divisible by 3 (and not by 5), replace it with
Fizz
. - If a number is divisible by 5 (and not by 3), replace it with
Buzz
. - If none of the above conditions hold, leave the number unchanged.
In mathematical notation, for an integer \(n\):
- If \(n \mod 3 = 0\) and \(n \mod 5 = 0\), output
FizzBuzz
. - If \(n \mod 3 = 0\) and \(n \mod 5 \neq 0\), output
Fizz
. - If \(n \mod 5 = 0\) and \(n \mod 3 \neq 0\), output
Buzz
. - Otherwise, output \(n\) itself.
Implement a program that reads the list from the standard input and prints the transformed list to the standard output.
inputFormat
The input consists of a single line containing space-separated integers. For example: 1 2 3 4 5
.
outputFormat
Output the transformed list as a single line of space-separated values. If a number is divisible by 3 and/or 5, output the corresponding string as described in the rules. Otherwise, output the number.## sample
1 2 3 4 5
1 2 Fizz 4 Buzz