#C13258. Stock Price Analyzer
Stock Price Analyzer
Stock Price Analyzer
You are given historical stock price data in CSV format via standard input. The first line of the input is the header "date,price", and each subsequent line contains a date in the format YYYY-MM-DD and a stock price (a floating-point number), separated by a comma.
Your task is to analyze this data and determine the record with the highest stock price and the record with the lowest stock price. In case of ties for the maximum or minimum price, choose the record that appears first in the input.
The output should consist of two lines:
- The first line should be in the format:
Max: <date> <price>
, indicating the date and the maximum stock price. - The second line should be in the format:
Min: <date> <price>
, indicating the date and the minimum stock price.
For example, if the input CSV is:
date,price 2022-01-01,100.0 2022-02-01,102.5 2022-03-01,105.0
Then the output should be:
Max: 2022-03-01 105.0 Min: 2022-01-01 100.0
Bonus: Let \(P_{\max}\) and \(P_{\min}\) denote the maximum and minimum stock prices, respectively. Your solution should correctly identify these values such that the price difference \(\Delta P = P_{\max} - P_{\min}\) is accurately computed (although you are not required to output this difference).
inputFormat
The input is given through standard input (stdin) and follows the CSV format. The first line is the header: date,price
. Each subsequent line contains a date (in YYYY-MM-DD
format) and a stock price (a float), separated by a comma.
Example:
date,price 2022-01-01,100.0 2022-02-01,102.5 2022-03-01,105.0
outputFormat
The output should be printed to standard output (stdout) and consist of two lines:
- The first line follows the format:
Max: <date> <price>
, indicating the date and the maximum stock price. - The second line follows the format:
Min: <date> <price>
, indicating the date and the minimum stock price.
Make sure there are no extra spaces or lines in the output.
## sampledate,price
2022-01-01,100.0
2022-02-01,102.5
2022-03-01,105.0
Max: 2022-03-01 105.0
Min: 2022-01-01 100.0
</p>