#C14874. Sales Summary Report Generator

    ID: 44571 Type: Default 1000ms 256MiB

Sales Summary Report Generator

Sales Summary Report Generator

You are given a CSV formatted sales data from standard input. The CSV contains a header row followed by rows with three fields: month, product, and sales. Some sales fields may be missing; treat any missing or empty sales value as 0.

Your task is to generate a summary report in JSON format with the following keys:

  • total_sales: the sum of all sales values.
  • average_sales_per_month: the average monthly total sales across all unique months. Round the result to one decimal place.
  • top_3_products: a list containing the names of the top 3 products with the highest overall sales. In case of ties, sort the products in lexicographical order.

The output JSON object should be printed to standard output.

Note: Use LaTeX format to express any formulas. For instance, the average is computed as \(\text{average}\ = \frac{\sum_{m=1}^{n} S_m}{n}\), where \(S_m\) is the total sales for month \(m\) and \(n\) is the number of unique months.

inputFormat

The input is provided via standard input (stdin) and consists of multiple lines in CSV format. The first line is a header: month,product,sales. Each subsequent line represents one record. For example:

month,product,sales
Jan,A,100
Jan,B,200
Feb,A,150
Feb,C,300
Mar,B,250
Mar,C,350

Empty fields for sales should be considered as 0.

outputFormat

Your program should output a single JSON object to standard output (stdout) that contains the keys:

  • total_sales: an integer
  • average_sales_per_month: a float rounded to one decimal place
  • top_3_products: a list of strings

For example:

{"total_sales":1350, "average_sales_per_month":450.0, "top_3_products":["C","B","A"]}
## sample
month,product,sales
Jan,A,100
Jan,B,200
Feb,A,150
Feb,C,300
Mar,B,250
Mar,C,350
{"total_sales":1350, "average_sales_per_month":450.0, "top_3_products":["C","B","A"]}