Create A State Machine For A Door Lock
Model a door with three states: CLOSED_UNLOCKED (initial), CLOSED_LOCKED, and OPEN.
Model a door with three states: CLOSED_UNLOCKED (initial), CLOSED_LOCKED, and OPEN. LOCK is valid only when CLOSED_UNLOCKED; UNLOCK only when CLOSED_LOCKED; OPEN only when CLOSED_UNLOCKED; CLOSE only when OPEN. Invalid commands leave the state unchanged and print ERROR. Valid commands print the resulting state.
Input format
First line Q; next Q lines LOCK, UNLOCK, OPEN or CLOSE.
Output format
Print ERROR for invalid commands; otherwise print CLOSED_UNLOCKED, CLOSED_LOCKED or OPEN.
Examples
5 LOCK OPEN UNLOCK OPEN CLOSE
CLOSED_LOCKED ERROR CLOSED_UNLOCKED OPEN CLOSED_UNLOCKED
Constraints
- 0 ≤ Q ≤ 100000
Related concepts
This early-access exercise uses standard input/output. More advanced concurrency challenges will use specialized class interfaces, instrumentation, and stress tests once the judging infrastructure is ready.
Loading Monaco C++ editor…
Checking whether the external C++ judge is available.
5 LOCK OPEN UNLOCK OPEN CLOSE
CLOSED_LOCKED ERROR CLOSED_UNLOCKED OPEN CLOSED_UNLOCKED