#95. 数组元素条件修改
数组元素条件修改
Array Modification
Background
Congcong is studying a special array transformation rule. He has an integer array and wants to perform a series of operations on it, updating certain elements based on specific conditions.
Problem Description
For each multiple of in the given array, change all the values following it to be that multiple of , until encountering another multiple of . So yields .
Input Format
Input is given from standard input in the following format.
a_1 a_2 ... a_n
Where are integer elements of the array, separated by spaces.
Output Format
Output is printed to standard output in the following format.
b_1, b_2, ..., b_n
Where are the elements of the modified array, separated by commas and spaces.
Sample
[2 10 3 4 20 5]
[2, 10, 10, 10, 20, 20]
[10 1 20 2]
[10, 10, 20, 20]
[10 1 9 20]
[10, 10, 10, 20]
Sample Explanation
For the first sample [2 10 3 4 20 5]:
- Element
2is not a multiple of , it remains unchanged. - Element
10is a multiple of . The subsequent elements3and4are changed to10. - Element
20is a multiple of . The subsequent element5is changed to20. The final array becomes[2, 10, 10, 10, 20, 20].
Constraints
Time limit: 1s, Memory limit: 1024KiB for each test case.