#K74507. Warehouse Management System

    ID: 34212 Type: Default 1000ms 256MiB

Warehouse Management System

Warehouse Management System

You are required to implement a warehouse management system that processes a series of commands. The system maintains a 100x100 grid representing warehouse cells. Each cell can store at most one item. Each item has a unique identifier and an associated quantity. The supported operations are:

  • add x y item_id quantity: Add a new item to the cell with coordinates \( x \) and \( y \). If the item already exists anywhere in the warehouse, or the target cell is occupied, output the corresponding error message.
  • remove x y item_id: Remove the item from the specified cell. If the item does not exist at that location, output an error.
  • move item_id x1 y1 x2 y2: Move an item from cell \( (x_1, y_1) \) to cell \( (x_2, y_2) \). If the item is not found at \( (x_1, y_1) \) or the destination cell is occupied, output an error.
  • query item_id: Query the current location and quantity of an item. If the item is not found, output a message stating so.

Commands are given one per line and the sequence is terminated by a line containing end. All error messages must exactly match the specifications.
The operations should follow the rules using the following conditions:

  • If you try to add an item that already exists, output: Item already exists.
  • If you try to add an item to an occupied cell, output: Location already occupied.
  • If you try to remove an item that is not in the specified location, output: Item not found at specified location.
  • If you try to move an item from a cell where it is not present, output: Item not found at specified initial location.
  • If you try to move an item to a cell that is already occupied, output: Destination location already occupied.

For a query command, if the item exists, output the coordinates and quantity in the format:

\( x\ y\ quantity \)

Otherwise, output:

\( item_id\ not\ found \)

inputFormat

The input will consist of several lines. Each line is a command. The commands can be one of the following forms:

  • add x y item_id quantity
  • remove x y item_id
  • move item_id x1 y1 x2 y2
  • query item_id

The sequence of commands is terminated by a line containing end. Inputs are read from stdin.

outputFormat

Output the result of each query command or any error messages that occur during the processing of commands. Each output should be printed on a new line to stdout.

## sample
add 5 5 item1 100
query item1
end
5 5 100

</p>