#C566. Summarize Sales Data from CSV

    ID: 49333 Type: Default 1000ms 256MiB

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:

  1. The total number of sales.
  2. The number of unique customers.
  3. 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:

  1. Total number of sales (an integer).
  2. Number of unique customers (an integer).
  3. 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