Warehouse Stocking

면접 대비

시간 제한1초메모리 제한2048 MB

요약
창고의 각 위치에 물건 하나만 보관할 수 있을 때 PUT, TAKE, FIND 연산을 처리하고, FIND마다 해당 물건이 있는 위치를 사전순으로 출력하거나 NOT FOUND를 출력한다.
난이도

보통10점 중 4점

유형
해시맵, 시뮬레이션, 정렬, 구현
정답자
아직 제출이 없습니다

문제

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

입력

The first line of input will be an integer 1≤N≤1051 \leq N \leq 10^5 representing how many lines of input are to follow.

The next NN 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 1010.

출력

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.

예제4

  1. 예제 1

    입력
    3
    PUT COMPUTER UPSTAIRS
    PUT COMPUTER DOWNSTAIRS
    FIND COMPUTER
    
    예상 출력
    DOWNSTAIRS UPSTAIRS
    
  2. 예제 2

    입력
    4
    PUT COMPUTER LECTUREHAL
    TAKE LECTUREHAL
    PUT COMPUTER CLOSET
    FIND COMPUTER
    
    예상 출력
    CLOSET
    
  3. 예제 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
    
  4. 예제 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