Kagisys
InterviewTime limit2sMemory limit512 MB
Simulate a door lock: for each scanned card ID, print whether it opens, closes, or is unknown, toggling the door state on known IDs.
- Level
Easy3 of 10
- Topics
- Hash map, Simulation, Implementation, String
- Solved
- No attempts yet
Problem
A room uses an electronic lock system that opens and closes a door with IC cards. The system works as follows.
When a user holds their IC card over the door, the ID of that IC card is passed to the system. If the ID is registered, the system unlocks the door when it is locked and locks it otherwise, printing a message in each case. If the ID is not registered, the system prints a message saying it is not registered, and neither unlocks nor locks the door.
Currently, N IDs (U1, U2, ..., UN) are registered in the system, and the door is locked. An IC card is held over the door M times, and the IDs are T1, T2, ..., TM in that order. Determine what messages the system prints.
Input
The input is given in the following format.
N
U1
U2
……
UN
M
T1
T2
……
TM
Output
For each of T1, T2, ..., TM, print on one line:
-
"Opened by " followed by the ID when the door is unlocked,
-
"Closed by " followed by the ID when the door is locked,
-
"Unknown " followed by the ID when the ID is not registered.
The door is locked in the initial state.
Constraints
-
N and M are integers
-
1 ≤ N ≤ 256
-
Ui is a string of 1 to 10 lowercase English letters
-
Ui are unique (Ui ≠ Uj if i ≠ j)
-
1 ≤ M ≤ 256
-
Ti is a string of 1 to 10 lowercase English letters