A task board records tasks starting, finishing, and being cleared. Process the events in order. Report the IDs cleared by the last cleanup and the IDs still running. Finished tasks wait for cleanup; no real programs are started.
Input: One line of space-separated events: SPAWN:id=name starts an ID, EXIT:id finishes it, and REAP clears finished IDs. The name is a label without spaces.
Output: Print the IDs removed by the most recent REAP, then the IDs still running, separated by one space. Sort each group numerically and join its IDs with commas. Use none for an empty group.
Input:
SPAWN:101=sleep SPAWN:102=worker EXIT:101 REAP
Output:
101 102
Explanation: Task 101 finishes and REAP removes it. Task 102 is still running, so the two groups are 101 and 102.
Input:
SPAWN:105=compile SPAWN:102=lint EXIT:105 EXIT:102 REAP
Output:
102,105 none
Explanation: Both tasks finish before cleanup. Sort their removed IDs as 102,105; no running IDs remain, so the second group is none.
Input:
SPAWN:201=server SPAWN:202=worker REAP
Output:
none 201,202
Explanation: Neither task has finished, so cleanup removes none. The running IDs are 201,202.
Input:
SPAWN:301=job EXIT:301 EXIT:301 REAP
Output:
301 none
Explanation: The second EXIT for 301 is ignored because it has already finished. Cleanup removes 301 once, and no task remains running.
Input:
SPAWN:10=a EXIT:10 REAP SPAWN:20=b SPAWN:30=c EXIT:20 REAP
Output:
20 30
Explanation: The first cleanup removes 10, but the final cleanup replaces that result with 20. Task 30 is still running, so print 20 30.
Can two sets represent running and finished IDs? Which result must each cleanup replace?
A shell must distinguish work that is running from work that has finished. Level 3 uses a similar state-tracking idea, but its input commands and output format are different.
System 1: Build a Command-Line Shell
Optional application of the idea. You write the System solution separately.
Read a command plan and identify its steps and output destination.
101 102