Problem H
Warehouse Stocking
CS@Mines is restocking on supplies and is looking to make an inventory management system for a warehouse which keeps those supplies.
Due to our warehouse constraints, we can only keep one item in any given location at a time! Therefore, we need to manage when items are taken and put into the warehouse inventory. Additionally, we only have at most $10$ copies of each item.
Additionally, professors and students are actively using the warehouse! While we are still unloading shipments, items may be taken out of the warehouse before more come in. There are three distinct events which can occur in the warehouse:
An item can be PUT into a specific location.
Someone can TAKE the item currently in the specified location, which removes it from the location.
Someone can FIND all of the locations that contain the specified item. Note that since there at most 10 copies of each item, this should return at most 10 locations.
Input
The first line of input will be an integer $1 \leq N \leq 10^5$ representing how many lines of input are to follow.
The next $N$ lines will each consist of one of the following operations:
A PUT operation, in the following format: PUT [ITEM] [LOCATION].
A TAKE operation, in the following format: TAKE [LOCATION]. There will never be a TAKE operation for a location that does not currently have an item.
A FIND operation, in the following format: FIND [ITEM] indicating that someone wants to look up the locations of a specific item.
All LOCATIONs and ITEMs will be strings of uppercase Latin letters (A-Z) of length at most $10$.
Output
For each FIND operation, output the location(s) which contain the ITEM specified by the FIND as a lexicographically sorted, space-separated list. Or, if the item cannot be found, print out: “NOT FOUND” (without the quotes).
The output of each FIND operation is based off previously seen operations; in other words, the PUT and TAKE operations are done in chronological order.
Sample Input 1 | Sample Output 1 |
---|---|
3 PUT COMPUTER UPSTAIRS PUT COMPUTER DOWNSTAIRS FIND COMPUTER |
DOWNSTAIRS UPSTAIRS |
Sample Input 2 | Sample Output 2 |
---|---|
4 PUT COMPUTER LECTUREHAL TAKE LECTUREHAL PUT COMPUTER CLOSET FIND COMPUTER |
CLOSET |
Sample Input 3 | Sample Output 3 |
---|---|
11 PUT PENCIL A PUT PAPER B PUT LAPTOP C TAKE B PUT LAPTOP D PUT LAPTOP E TAKE E PUT PEN F TAKE A FIND LAPTOP FIND PAPER |
C D NOT FOUND |
Sample Input 4 | Sample Output 4 |
---|---|
22 PUT DONUTS A PUT COFFEE B PUT TOAST C PUT KETTLE D PUT DONUTS E PUT MUG F PUT MICROWAVE G PUT MUG H PUT MILK I PUT COFFEE J FIND DONUTS TAKE A TAKE B TAKE C TAKE D TAKE E TAKE F FIND MUG TAKE G TAKE I TAKE J FIND MICROWAVE |
A E H NOT FOUND |