#C6025. Analyze Product Profitability

    ID: 49740 Type: Default 1000ms 256MiB

Analyze Product Profitability

Analyze Product Profitability

You are given one or more datasets describing a list of products. Each dataset begins with a positive integer n representing the number of products, followed by n product descriptions. Each product description is given as a line containing a product ID, an ignored parameter, the cost, and the price. The profitability for a product is computed as \( \frac{\text{price}}{\text{cost}} \). Your task is to sort the products of each dataset in descending order of profitability. In case of ties, order the products in ascending lexicographical order of their product IDs. After listing the sorted product IDs of a dataset, output a line containing a single '#' symbol. The input terminates with a line containing a single 0, which should not be processed.

inputFormat

The input is read from standard input (stdin) and consists of multiple datasets. Each dataset is formatted as follows:

  • A line containing a positive integer n (\(1 \le n \le 1000\)) representing the number of products.
  • Followed by n lines, each containing a product description in the format: product_id ignored_value cost price, where cost and price are positive numbers.

The input terminates with a line containing the single digit 0 (zero), which indicates the end of input and should not be processed.

outputFormat

For each dataset, output the sorted product IDs, one per line, in descending order of profitability (price/cost). In case of equal profitability, sort by product ID in ascending order. After each dataset, output a line with a single '#' character. The results should be printed to standard output (stdout).

## sample
3
widget1 10 50 200
widget2 15 30 150
widget3 20 40 160
2
gadget1 12 60 240
gadget2 8 50 200
0
widget2

widget1 widget3

gadget1 gadget2 #

</p>