Window Switching
InterviewTime limit2sMemory limit1024 MB
Simulate a circular list of running applications, inserting new ones at the front and rotating on each Alt+Tab, then print each window that becomes active.
- Level
Medium4 of 10
- Topics
- Simulation, Array, Implementation, Linked list
- Solved
- No attempts yet
Problem
When a user works in the Windows operating system, several applications are often running. Each application runs in its own window. To switch between windows, the user presses <<Alt+Tab>>. This combination activates the window the user was working in before moving to the currently active window.
To switch to another window, the user can press <<Alt>> and then, without releasing it, press <<Tab>> several times. To determine which window becomes active, use the following model. Suppose applications are running. The operating system arranges the applications in a list ordered by decreasing time of last activity. That is, the application whose window is currently active is first in the list, the application whose window was active before that is second, and so on.
If the user presses <<Alt>> and then, without releasing it, presses <<Tab>> times, the window of the application at position in the list becomes active. Here is the remainder when is divided by . In other words, the operating system treats the list as circular, going from the last element back to the first.
When a new application starts, it is added to the front of the list.
A sequence of user actions is given, where each action is either starting an application or switching between windows. Output the order in which the user worked with the applications.
Input
The first line of the input file contains an integer , the number of user actions (). The next lines describe the user actions.
Starting an application is described by a line <<Run <{\sl application name}>\relax>>. Here <<\relax<{\sl application name}>\relax>> is a string of at most 100 Latin letters, digits, and spaces. It is separated from the word <<Run>> by exactly one space. All application names are distinct. Uppercase and lowercase letters are considered different.
Switching between applications is described by a line <<Alt+Tab+\dots+Tab>>, where the substring <<+Tab>> is repeated exactly as many times as the user pressed <<Tab>> without releasing <<Alt>>. This count does not exceed 100.
The first command in the input file is always a <<Run>> command.
Output
Output lines: the names of the applications the user worked with, in the order in which their windows became active.