#C1659. Warehouse Management
Warehouse Management
Warehouse Management
You are in charge of managing a warehouse that operates with a simple stack-based inventory system. The warehouse supports two types of operations:
- Retrieval Operation: Represented by a line containing the number
1
. This operation attempts to retrieve (pop) the most recently stocked material from the warehouse. If the warehouse is empty, outputWarehouse Empty
. - Stocking Operation: Represented by a line starting with
2
followed by an integer material_id. This operation stocks the material into the warehouse (push operation).
The process follows a Last-In-First-Out (LIFO) mechanism. In other words, if the operations are represented as a sequence, then whenever a retrieval occurs, the most recent stocking is removed and its material_id is output.
For example, consider the operations below:
7 1 2 55 2 88 1 2 12 1 1
The expected outputs for the retrieval operations are as follows (in order):
\(Warehouse\ Empty,\ 88,\ 12,\ 55\)
Implement the functions needed to parse the input and manage the warehouse accordingly.
inputFormat
The input is provided via standard input with the following format:
- The first line contains an integer \(n\) indicating the number of operations.
- The next \(n\) lines each represent an operation. An operation is either:
- A single integer
1
representing a retrieval operation. - A line starting with
2
followed by a space and an integer material ID, representing a stocking operation.
See the sample input for clarification.
outputFormat
The output should be printed to standard output and consist of the results of each retrieval operation in the order they were processed. Each result must be printed on a new line.
If a retrieval operation is performed on an empty warehouse, output Warehouse Empty
for that operation.
7
1
2 55
2 88
1
2 12
1
1
Warehouse Empty
88
12
55
</p>