#C14888. Warehouse Inventory Manager

    ID: 44586 Type: Default 1000ms 256MiB

Warehouse Inventory Manager

Warehouse Inventory Manager

In this problem, you are required to implement a warehouse inventory manager. Each inventory item has a unique identifier ($\text{item\_id}$), a name, a quantity, and a price. Your program should maintain the inventory and support the following operations:

  • ADD: Add an item to the inventory. Ensure that the $\text{item\_id}$ is unique. If the item is added successfully, output "Item added successfully."; otherwise, output "Error: Item with this ID already exists.".
  • REMOVE: Remove an item from the inventory by its item ID. If successful, output "Item removed successfully."; if the item does not exist, output "Error: Item ID does not exist.".
  • UPDATE: Update the quantity and price of an existing item identified by its item ID. Output "Item updated successfully." on success, or "Error: Item ID does not exist." if the item is not found.
  • SEARCH: Search for an item by either item_id or name. For each matching item, output its details in the format item_id name quantity price in the order they were added. If no matching item is found, output "None".

All inputs are read from stdin and outputs should be written to stdout.

inputFormat

The first line contains an integer $N$, the number of commands to process. The following $N$ lines each contain a command in one of the following formats:

  • ADD item_id name quantity price
  • REMOVE item_id
  • UPDATE item_id quantity price
  • SEARCH field value

Note: For the SEARCH command, field is either item_id or name. When field is item_id, value is an integer; otherwise, it is a string.

outputFormat

For each command, output the corresponding response on a separate line:

  • ADD, REMOVE, and UPDATE commands output a single message.
  • SEARCH outputs one line per matching item in the format item_id name quantity price. If no items match, output None.
## sample
6
ADD 1 Widget 10 2.99
ADD 2 Gadget 5 3.99
SEARCH item_id 1
UPDATE 1 20 3.99
SEARCH name Widget
REMOVE 2
Item added successfully.

Item added successfully. 1 Widget 10 2.99 Item updated successfully. 1 Widget 20 3.99 Item removed successfully.

</p>