#C941. Average Stock Prices

    ID: 53500 Type: Default 1000ms 256MiB

Average Stock Prices

Average Stock Prices

You are given multiple datasets containing stock records. Each record is given in the format

$$\texttt{SYMBOL DATE PRICE}$$

where SYMBOL is a stock ticker, DATE is a date string, and PRICE is a floating-point number.

For each dataset, calculate the average stock price for each unique symbol, format the average to two decimal places, and sort the output in alphabetical order of symbols. After processing each dataset, output a line containing a single # to indicate the end of that dataset.

The input ends with a line containing a single 0 (zero), which should not be processed.

inputFormat

The input is read from standard input (stdin) and consists of multiple datasets. Each dataset starts with an integer N representing the number of records, followed by N lines each containing a record in the format SYMBOL DATE PRICE. The input is terminated by a line containing 0.

outputFormat

For each dataset, output the average price per stock symbol on separate lines, formatted as SYMBOL AVERAGE_PRICE where AVERAGE_PRICE is rounded to two decimal places. The results for each dataset should be sorted in alphabetical order by the stock symbol. After each dataset, output a line containing a single #.## sample

5
AAPL 2023-07-14 145.87
GOOGL 2023-07-14 2725.82
MSFT 2023-07-14 289.67
AAPL 2023-07-15 148.56
GOOGL 2023-07-15 2700.30
0
AAPL 147.22

GOOGL 2713.06 MSFT 289.67 #

</p>