#C13415. Sorted Products Inventory

    ID: 42951 Type: Default 1000ms 256MiB

Sorted Products Inventory

Sorted Products Inventory

You are given CSV data of products from standard input. The CSV contains a header and multiple rows. The header has the columns: product_id, product_name, price, and quantity. Your task is to compute the inventory value for each product using the formula (inventory_value = price \times quantity) and append this value as a new column. Then, sort all the products in descending order of their inventory values and print the entire CSV (including a new header row) to standard output.

For example, if the input is:

product_id,product_name,price,quantity 1,Product A,10.0,2 2,Product B,8.0,5 3,Product C,15.0,3

Then, the computed inventory values are 20.0, 40.0, and 45.0 respectively and the sorted output should be:

product_id,product_name,price,quantity,inventory_value 3,Product C,15.0,3,45.0 2,Product B,8.0,5,40.0 1,Product A,10.0,2,20.0

inputFormat

The input is provided through standard input (stdin) as CSV text. The first line is the header: "product_id,product_name,price,quantity". Subsequent lines contain the product data separated by commas.

outputFormat

Output the processed CSV data to standard output (stdout). The first line should be the header "product_id,product_name,price,quantity,inventory_value", followed by the product records sorted in descending order based on inventory value. Each inventory value is calculated using (price \times quantity), and must be displayed with one decimal place.## sample

product_id,product_name,price,quantity
1,Product A,10.0,2
2,Product B,8.0,5
3,Product C,15.0,3
product_id,product_name,price,quantity,inventory_value

3,Product C,15.0,3,45.0 2,Product B,8.0,5,40.0 1,Product A,10.0,2,20.0

</p>