Question
Extreme Fizz Buzz Fizz Buzz is a classic Computer Science problem about Selection. For an integer x, print: Fizz if x is only divisible by
Extreme Fizz Buzz
Fizz Buzz is a classic Computer Science problem about Selection. For an integer x, print:
Fizz if x is only divisible by 3,
Buzz if x is only divisible by 5,
FizzBuzz if x is divisible by both 3 and 5,
the number x if it is not divisible by both 3 and 5.
This problem is the extreme version of Fizz Buzz. You are given a list of K distinct
integers A and a list of K characters S. Both lists are numbered from 1 to K. The
integer Ai corresponds to the character Si
.
Denote B as the subset of A. There will be a rule for each possible subset: if an integer
x is only divisible by all elements in B, print a string which is the concatenation of the
corresponding character of each element in B, sorted by the index in ascending order.
However, if B is an empty subset, print the first digit of x instead.
Does it look complicated? Do not worry, as it is just a generalization of the regular Fizz
Buzz. For example, if A = [3, 5] and S = [F, B], you will get the normal Fizz Buzz
problem. You can also check the Sample Test Cases for further understanding.
Your task is simple. Given the array A and S, with all rules from the subset of A, print
the Extreme Fizz Buzz from 1 to N.
Format Input
The first line consists of 2 integers N and K.
The second line consists of a string S which has exactly K lower-case latin alphabet
characters.
The third line consists of K integers A1, A2, . . . , AK.
Format Output
Output N lines. The i-th line is the Extreme Fizz Buzz of i, where i is integer from 1 to
N.
Constraints
1 N, K 100000
1 Ai 100000
It is guaranteed that the integers in A are distinct
It is guaranteed that the characters in S are upper-case latin alphabet characters
Sample Input 1 (standard input)
15 2
FB
3 5
Sample Output 1 (standard output)
1
2
F
4
B
F
7
8
F
B
1
F
3
4
FB
Sample Input 2 (standard input)
15 2
BF
3 5
Sample Output 2 (standard output)
1
2
B
4
F
B
7
8
B
F
1
B
3
4
BF
Sample Input 3 (standard input)
13 3
JLB
2 4 3
Sample Output 3 (standard output)
1
J
B
JL
5
JB
7
JL
B
J
1
JLB
3
Note : Use C Language , Dont Use Stdlib as you can,make a new code with stdio.h or string.h only
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started