50. State Machine with Enums

We have already declared an enum class State with values: Idle, Busy, Error.
A helper function toString(State s) is also provided.

The system starts in 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"IdleBusy
  • "done"BusyIdle
  • "fail"BusyError

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:

Busy 

 

Example 2

Input:

2
start fail

Output:

Error 

 

 

 

 

 

 

Loading...

Input

3 start done start

Expected Output

Busy