#K94922. Evaluate Stock Portfolio
Evaluate Stock Portfolio
Evaluate Stock Portfolio
You are given a table of stock prices for three companies over n days. Each day, the table provides three integers representing the stock prices of the companies.
Your task is to compute two things:
- The average stock price for each company over the n days. The average should be calculated as
$$\frac{\text{sum of prices}}{n}$$
and formatted to exactly 2 decimal places. - The percentage change of the stock price for each company from the first day to the last day. The percentage change is given by
$$\frac{p_{last} - p_{first}}{p_{first}} \times 100$$
If the price on the first day is zero, consider the percentage change to be 0.00%.
The result should be printed in two lines. The first line contains the three average prices separated by a space, and the second line contains the three percentage changes (each appended with a '%' symbol) separated by a space.
inputFormat
The input is given via standard input (stdin) and has the following format:
n price1_1 price1_2 price1_3 price2_1 price2_2 price2_3 ... pricen_1 prinen_2 prinen_3
Where:
n
is an integer representing the number of days.- Each of the next n lines contains 3 integers, representing the stock prices for the three companies on that day.
outputFormat
The output should be printed to standard output (stdout) in the following format:
avg1 avg2 avg3 perc1% perc2% perc3%
Each average and percentage change must be formatted to exactly 2 decimal places. Note that for percentage changes, append a '%' symbol immediately after the number.
## sample5
100 150 200
110 140 210
120 130 220
130 120 230
140 110 240
120.00 130.00 220.00
40.00% -26.67% 20.00%
</p>