#C6414. Automated Fruit Vendor
Automated Fruit Vendor
Automated Fruit Vendor
You are tasked with simulating the operations of an automated fruit vendor machine. The machine supports two operations on fruit inventory:
- restock: Increase the quantity of a given fruit. Format:
restock fruit_name quantity
. - sell: Sell a specified quantity of a fruit. Format:
sell fruit_name quantity
.
During a sell operation, if the inventory has at least the requested quantity, the sale is successful and the program outputs:
$Sold\;fruit\_name$
Otherwise, it outputs:
$Insufficient\;quantity\;fruit\_name$
The operations are processed in sequence. The problem requires reading standard input (stdin) where the first line is an integer n denoting the number of operations followed by n lines with each operation. The output should be printed on standard output (stdout) with each result on a new line.
inputFormat
The first line of the input contains an integer n representing the number of operations.
The next n lines each contain an operation in one of the following formats:
restock fruit_name quantity
sell fruit_name quantity
outputFormat
For each sell
operation, output a line with the result:
- If the sale is successful, print
Sold fruit_name
. - If there is insufficient quantity, print
Insufficient quantity fruit_name
.
No output is produced for restock
operations.
8
restock apple 50
restock orange 30
sell apple 25
sell orange 40
restock banana 100
sell banana 35
restock orange 50
sell orange 70
Sold apple
Insufficient quantity orange
Sold banana
Sold orange
</p>