#C566. Summarize Sales Data from CSV
Summarize Sales Data from CSV
Summarize Sales Data from CSV
You are given a CSV formatted input where each record represents a sale. The first line of the input is a header with the following columns: sale_id
, customer_id
, and sale_amount
. Each subsequent line contains the details for one sale.
Your task is to compute and output three values:
- The total number of sales.
- The number of unique customers.
- The average sale amount, computed as (\frac{\text{total sale amount}}{\text{number of sales}}) (if the number of sales is greater than 0; otherwise, the average sale amount is 0).
Note that when formatting the average sale amount, it should be printed with exactly two decimal places if there is any fractional part.
inputFormat
The input is provided via standard input (stdin) as CSV text. The first line is the header "sale_id,customer_id,sale_amount" followed by one or more lines of sale records. Each sale record is a comma-separated line containing:
- sale_id (an integer),
- customer_id (an integer or string), and
- sale_amount (a floating point number).
It is possible that there are no sale records (i.e. only the header is provided).
outputFormat
Output three values on a single line separated by spaces:
- Total number of sales (an integer).
- Number of unique customers (an integer).
- Average sale amount (a floating point number displayed with two decimal places).
For example, an output might look like:
4 3 34.99## sample
sale_id,customer_id,sale_amount
1,1001,29.99
2,1002,49.99
3,1001,19.99
4,1003,39.99
4 3 34.99