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, printthe 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 ≤ 50000 • 1 ≤ Ai ≤ 50000 • 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 Explanation In the first sample, the given rule is similar to the regular Fizz Buzz. However, print “F” instead of “Fizz”, print “B” instead of “Buzz”, print “FB” instead of “FizzBuzz”, and print the first digit of x instead of the number x. In the second sample, the given rule is similar to the regular Fizz Buzz. However, print “B” instead of “Fizz”, print “F” instead of “Buzz”, and print “BF” instead of “FizzBuzz”, print the first digit of x instead of the number x. In the third sample, 2 corresponds to “J”, 4 corresponds to “L”, and 3 corresponds to “B”. Using the given A and S, there are exactly 8 rules, which are also the number of subset in A: • If x is only divisible by 2, print “J” • If x is only divisible by 4, print “L” • If x is only divisible by 3, print “B” • If x is only divisible by 2 and 4, print “JL” • If x is only divisible by 2 and 3, print “JB” • If x is only divisible by 4 and 3, print “LB” • If x is only divisible by 2, 4, and 3, print “JLB” • If x is not divisible by 2, 4, and 3, print the first digit of x instead #include int main(){ long long int n, k; scanf("%lld %lld\n", &n, &k); char S[55000];long long int A[55000];char ch; for (long long int a = 0; a < k; a++){ scanf("%c", &S[a]); } for (long long int a = 0; a < k; a++){ scanf("%lld", &A[a]); } for (long long int a = 1; a <= n; a++){ char subset[k + 1]; long long int index = -1; for (long long int b = 0; b < k; b++){ if ((a % A[b]) == 0) { index++; subset[index] = S[b]; } } if (index == -1){ printf("%lld\n", a % 10); } else{ for(long long int b = 0; b <= index; b++){ printf("%c", subset[b]); } printf("\n"); } } return 0; } Sir please fix this code by making the looping is only 4 looping, not

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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 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, printthe 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 ≤ 50000
• 1 ≤ Ai ≤ 50000
• 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

Explanation
In the first sample, the given rule is similar to the regular Fizz Buzz. However, print “F” instead of “Fizz”, print “B” instead of “Buzz”, print “FB” instead of “FizzBuzz”, and print the first digit of x instead of the number x.
In the second sample, the given rule is similar to the regular Fizz Buzz. However, print “B” instead of “Fizz”, print “F” instead of “Buzz”, and print “BF” instead of “FizzBuzz”, print the first digit of x instead of the number x.
In the third sample, 2 corresponds to “J”, 4 corresponds to “L”, and 3 corresponds to “B”. Using the given A and S, there are exactly 8 rules, which are also the number of subset in A:
• If x is only divisible by 2, print “J”
• If x is only divisible by 4, print “L”
• If x is only divisible by 3, print “B”
• If x is only divisible by 2 and 4, print “JL”
• If x is only divisible by 2 and 3, print “JB”
• If x is only divisible by 4 and 3, print “LB”
• If x is only divisible by 2, 4, and 3, print “JLB”
• If x is not divisible by 2, 4, and 3, print the first digit of x instead

#include <stdio.h>
int main(){
long long int n, k;
scanf("%lld %lld\n", &n, &k);
char S[55000];long long int A[55000];char ch;
for (long long int a = 0; a < k; a++){
scanf("%c", &S[a]);
}
for (long long int a = 0; a < k; a++){
scanf("%lld", &A[a]);
}
for (long long int a = 1; a <= n; a++){
char subset[k + 1];
long long int index = -1;
for (long long int b = 0; b < k; b++){
if ((a % A[b]) == 0) {
index++;
subset[index] = S[b];
}
}
if (index == -1){
printf("%lld\n", a % 10);
}
else{
for(long long int b = 0; b <= index; b++){
printf("%c", subset[b]);
}
printf("\n");
}
}
return 0;
}

Sir please fix this code by making the looping is only 4 looping, not 5 looping, thx. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education