#C4377. Implement Custom Array Operations
Implement Custom Array Operations
Implement Custom Array Operations
You are required to implement a class called CustomArray
that supports four operations. Each operation returns a sequence as follows:
- Factorial Sequence: Given an integer \(n\), return a list of the first \(n\) factorials. For example, for \(n=5\) the output should be: \(1\ 2\ 6\ 24\ 120\).
- Geometric Progression: Given integers \(n\), \(start\), and \(ratio\), return a list of the first \(n\) terms of a geometric progression starting at \(start\) with a common ratio \(ratio\). For instance, input
5 1 2
should produce: \(1\ 2\ 4\ 8\ 16\). - Pascal's Triangle Row: Given an integer \(n\), return the \(n\)th row of Pascal's Triangle. The 0th row is defined as [1]. For example, for \(n=5\) the output should be: \(1\ 5\ 10\ 10\ 5\ 1\).
- Fibonacci Sequence: Given an integer \(n\), return a list of the first \(n\) Fibonacci numbers starting from 0. For example, for \(n=5\) the output is: \(0\ 1\ 1\ 2\ 3\).
The program will read multiple queries from standard input. Each query specifies an operation and its parameters. Your task is to implement the operations so that they can handle all queries and produce correct outputs.
inputFormat
Input is read from standard input and begins with an integer (T) representing the number of queries. Each of the following (T) lines contains a query in one of the following formats:
F n
— Print the factorial sequence for integer \(n\) (if \(n = 0\), output an empty line).G n start ratio
— Print the geometric progression of \(n\) terms beginning withstart
and common ratioratio
.P n
— Print the \(n\)th row of Pascal's Triangle (for \(n = 0\), the output is1
).B n
— Print the Fibonacci sequence of the first \(n\) numbers (if \(n = 0\), output an empty line).
outputFormat
For each query, output a single line to standard output containing the requested sequence. The numbers in the sequence should be separated by a space. If the sequence is empty, output an empty line.## sample
4
F 5
G 5 1 2
P 5
B 5
1 2 6 24 120
1 2 4 8 16
1 5 10 10 5 1
0 1 1 2 3
</p>