#K37822. Traffic Light Simulation
Traffic Light Simulation
Traffic Light Simulation
You are given a simulation of a traffic light system for a pedestrian crossing. The light has three states:
- Green for 60 seconds,
- Yellow for 5 seconds,
- Red for 55 seconds.
The simulation works cyclically: after Green comes Yellow, then Red, and finally Green again. Given an initial state and an elapsed time in seconds, your program should determine the current state and the remaining time in that state before a transition occurs.
The transition mechanism can be expressed mathematically as follows:
\[ \text{if } t < T_{state} \text{ then output } (\text{state}, T_{state} - t)\]
Otherwise, subtract \(T_{state}\) from \(t\) and move to the next state.
You need to process multiple test cases from standard input. The input terminates when a line containing "END 0" is encountered.
inputFormat
The input consists of several lines. Each line (except the last one) contains a string and an integer separated by space. The string represents the initial state (which can be either Green
, Yellow
, or Red
) and the integer is the elapsed time in seconds. The input ends with a line "END 0" which should not be processed.
For example:
Green 30 Yellow 3 Red 40 END 0
outputFormat
For each test case, output a line containing the current state and the remaining time (in seconds) separated by a space.
For example, corresponding to the above input, the output should be:
Green 30 Yellow 2 Red 15## sample
Green 30
Yellow 3
Red 40
END 0
Green 30
Yellow 2
Red 15