We have already declared an enum class State with values: Idle, Busy, Error.A helper function toString(State s) is also provided.
enum class State
Idle
Busy
Error
toString(State s)
The system starts in State::Idle.
State::Idle
Your task is to process a sequence of input commands and update the system state based on the following state transition rules:
"start"
"done"
"fail"
If a command does not match a valid transition for the current state, it is ignored and the state remains unchanged.
Once the system enters the Error state, all further commands are ignored.
After processing all commands, print the final state.
Example 1
Input:
3 start done start
Output:
Example 2
2 start fail
Test Cases
Test Results
Input
Expected Output