68. State Machine with Enums

 We have already declared an enum class State with values: IdleBusyError.
 We have also provided a helper function toString(State s).
 
The program starts in State::Idle.

Your task is to implement the logic that checks the sequence of input commands ("start", "done", "fail") and assigns the correct state transitions:

  • "start" :  Idle → Busy
  • "done" : Busy → Idle
  • "fail" : Busy → Error
     

Finally, print the final state.

 

Example
 Input:

3
start done start

Output:

Busy

 

Input:

2
start fail

Output:

Error

 

Loading...

Input

3 start done start

Expected Output

Busy