#C6065. Smart Cookbook
Smart Cookbook
Smart Cookbook
In this problem, you are required to implement a simple smart cookbook system. The cookbook maintains a collection of ingredients and their quantities. There are three types of operations available:
-
Add Ingredient: Adds an ingredient with the specified quantity. If the ingredient already exists, its quantity is updated to the new value. This operation is denoted by the operation code
1
. -
Update Quantity: Updates the quantity of an existing ingredient by adding the provided quantity. If the ingredient does not exist, it will be added with the given quantity. This operation is denoted by the operation code
2
. -
Query Quantity: Queries the current quantity of a specified ingredient. If the ingredient is not present in the cookbook, output a message in the format: (\texttt{ingredient_name does not exist}). This operation is denoted by the operation code
3
.
The input starts with an integer (n) ((1 \le n \le 10^5)) which represents the number of operations. Each of the next (n) lines contains an operation in one of the following formats:
1 ingredient_name quantity
for adding an ingredient,2 ingredient_name quantity
for updating an ingredient's quantity,3 ingredient_name
for querying an ingredient.
inputFormat
The first line of input contains an integer (n), the number of operations. The following (n) lines each describe an operation in one of the following formats:
1 ingredient_name quantity
(add operation)2 ingredient_name quantity
(update operation)3 ingredient_name
(query operation)
outputFormat
For each query operation (operation code 3), output the current quantity of the ingredient. If the ingredient does not exist in the cookbook, output a message in the following format: ingredient_name does not exist
.## sample
5
1 sugar 500
3 sugar
2 sugar 200
3 sugar
3 salt
500
700
salt does not exist
</p>