The Mexican Hat Dance

3.4

14 votes
Easy-Medium
Problem

Description

A popular party game in Mexico and the USA is called the Mexican Hat game. A bunch of people arrange themselves into a circle and a sombrero is given to every person in the circle except one. Music will start playing and someone from outside the circle yells “LEFT”, “RIGHT” or “STOP”, at which point, the persons with a hat will pass it to the next person on the left or right, respectively. When a STOP is heard, the music stops, the person without a hat is removed from the circle, that person is considered out. A new person in the circle will remove their hat before the music starts again and the last person on the circle with a hat wins! Make a program that will simulate the game.

Input Format

The first line of input contains two integers m and n. m is the number of players and n is the index for the first player without a hat (Note that indexing starts at 0). Each succeeding line is one round of play consisting of a series of LEFT, RIGHT commands separated by spaces. The last command in each command line will always be STOP X, where X is an integer, which is the index of a player who gets their hat removed before the music starts for the next round.

Output Format

Output the words “Player X is kicked out!” where X is the player’s index who gets kicked out each round, in every line. “Player Y wins!” should be displayed when player Y wins the game.

Sample Input
5 0 
RIGHT RIGHT LEFT LEFT RIGHT RIGHT RIGHT STOP 2
LEFT LEFT LEFT LEFT RIGHT STOP 0
RIGHT RIGHT LEFT LEFT RIGHT LEFT STOP 1
LEFT LEFT LEFT LEFT LEFT RIGHT STOP 1
Sample Output
Player 3 is kicked out!
Player 4 is kicked out!
Player 0 is kicked out!
Player 2 is kicked out!
Player 1 wins!
Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?