#C14461. Total Sales by Product
Total Sales by Product
Total Sales by Product
You are given a CSV file containing sales records. Each record has four fields: Date, Product, Region, and Sales. The Date is given in the format (YYYY-MM-DD). Your task is to compute the total sales for each product in a specified region over a given date range. Note that if the CSV file is missing any of the required columns or if the start or end date is invalid, then no valid data can be found and you should output "No Data". If no sales record matches the filtering criteria (date range and region), output "No Data". The output should list each product that qualifies along with the sum of its sales, with each product printed on a separate line with the product name followed by its total sales. The output should be sorted in lexicographical order based on the product names.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (N) denoting the number of lines in the CSV file (including the header). The next (N) lines describe the CSV file content. Following that, there are three more lines: the first is the start date, the second is the end date (both in the format (YYYY-MM-DD)), and the third is the region to filter by.
For example:
7 Date,Product,Region,Sales 2023-01-01,Product A,Region 1,100 2023-01-05,Product B,Region 1,150 2023-02-01,Product A,Region 1,200 2023-03-01,Product A,Region 1,300 2023-03-05,Product B,Region 1,250 2023-03-10,Product A,Region 2,150 2023-01-01 2023-03-31 Region 1
outputFormat
Output to standard output (stdout). For each product that has sales records matching the criteria, print a line containing the product name and its total sales amount separated by a space. The products must be output in lexicographical order of their names. If no valid data is found (due to an invalid date, missing columns, or no matching records), print exactly one line containing "No Data".## sample
7
Date,Product,Region,Sales
2023-01-01,Product A,Region 1,100
2023-01-05,Product B,Region 1,150
2023-02-01,Product A,Region 1,200
2023-03-01,Product A,Region 1,300
2023-03-05,Product B,Region 1,250
2023-03-10,Product A,Region 2,150
2023-01-01
2023-03-31
Region 1
Product A 600
Product B 400
</p>