#C2906. Stock Transaction Log Statistics
Stock Transaction Log Statistics
Stock Transaction Log Statistics
You are given a series of transaction logs. Each log is a string formatted as:
TIMESTAMP ACTION SYMBOL PRICE
The TIMESTAMP is given in the format YYYY-MM-DD hh:mm:ss
, ACTION can be BUY or SELL (this field is not used in the computation), SYMBOL represents the stock symbol and PRICE is a floating point number.
Your task is to compute, for each distinct stock symbol, the maximum price, minimum price, and the average price. The average price is calculated as \( \displaystyle \text{avg} = \frac{\sum prices}{n} \) and should be rounded to two decimal places.
The results should be output in lexicographical order by the stock symbol. For each symbol, print the symbol and its corresponding maximum, minimum, and average prices each on a new line.
inputFormat
The input is read from standard input (stdin). The first line contains an integer \(N\), the number of transaction logs. The next \(N\) lines each contain a transaction log in the following format:
TIMESTAMP ACTION SYMBOL PRICE
For example:
5 2023-01-01 09:00:00 BUY APPLE 150.00 2023-01-01 10:00:00 SELL APPLE 155.00 2023-01-01 11:00:00 BUY GOOGLE 1000.00 2023-01-01 12:00:00 SELL GOOGLE 1015.00 2023-01-01 13:00:00 BUY APPLE 152.00
outputFormat
The output is written to standard output (stdout). For each distinct stock symbol (sorted in lexicographical order), output 4 lines:
- The stock symbol
- The highest price (formatted with 2 decimal places)
- The lowest price (formatted with 2 decimal places)
- The average price (formatted with 2 decimal places)
For instance, for the sample input above, the expected output is:
APPLE 155.00 150.00 152.33 GOOGLE 1015.00 1000.00 1007.50## sample
5
2023-01-01 09:00:00 BUY APPLE 150.00
2023-01-01 10:00:00 SELL APPLE 155.00
2023-01-01 11:00:00 BUY GOOGLE 1000.00
2023-01-01 12:00:00 SELL GOOGLE 1015.00
2023-01-01 13:00:00 BUY APPLE 152.00
APPLE
155.00
150.00
152.33
GOOGLE
1015.00
1000.00
1007.50
</p>