#K76937. Simulate Console Price Fluctuations
Simulate Console Price Fluctuations
Simulate Console Price Fluctuations
You are given the initial prices of two gaming consoles, Console A and Console B, and a number of months to simulate their price changes. In each month, both consoles' prices are updated by multiplying with the same factor (1+r), where (r) is a random number uniformly chosen from ([-0.05,0.05]). The objective is to determine the month at which the absolute price difference between the two consoles is the smallest, and to report that month along with the smallest difference (rounded to two decimal places).
The process is as follows:
- For each month from 1 to (n), generate a random percentage (r) from ([-0.05,0.05]).
- Update both prices: (Price = Price \times (1+r)).
- Compute the absolute difference between the two updated prices.
- Track the month where this difference is minimized.
For reproducibility, your solution should initialize the random number generator with a fixed seed (42). The program will read three space-separated inputs from standard input: the initial price of Console A, the initial price of Console B, and the number of months (n). It will then output two numbers: the month with the smallest price difference and the smallest price difference (rounded to 2 decimals).
inputFormat
Input consists of three space-separated values provided via standard input: the initial price for Console A (float), the initial price for Console B (float), and the number of months (integer).
outputFormat
Output two values separated by a space on a single line: the month number (integer) at which the smallest price difference occurs, and the smallest price difference (float) rounded to two decimal places.## sample
500 500 12
1 0.00