#C6065. Smart Cookbook

    ID: 49784 Type: Default 1000ms 256MiB

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:

  1. 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.

  2. 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.

  3. 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.
Note that quantity is an integer. For every query operation, you should output the current quantity of the ingredient or an error message if the ingredient does not exist.

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)
Each ingredient_name is a string without spaces and quantity is an integer.

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>