Self Card-game
Time Limit: 1 Second Memory Limit: 32768 KB
FatPig is now enjoying his summer vocation in his hometown named "Pigsty". Being free from all the textbooks and horrible exams, he finds nothing to do, so he invents a card game that can be played without other participants. During his game, he uses a deck of 52 playing cards. Cards are dealt from the top of the deck. He begins the game by dealing out seven cards, forming seven piles from left to right. When the game on, in each turn he always deals a card out from the deck and puts it on one pile from left to right in sequences. (After dealing the card out on the rightmost pile, he will turn to the leftmost pile.) For each pile, if the latest dealt-out card has the same value with some old cards in this pile, then all the cards between these them will be removed from this pile and sent back to the deck. These cards will always be put on the bottom of the deck, For example:
One pile deck Before 1, 2, 3, 4, 5, 6, 3 3, 3, 5, 7 After 1, 2 3, 3, 5, 7, 3, 4, 5, 6 , 3
If all the cards of a pile are taken back to the deck, then this pile will "disappear", and this pile will be skipped when dealing out the deck cards. If all the seven piles disappear, FatPig will win the game. If some piles still exist when all the deck cards are dealt out. FatPig will lose the game. And there are also some instances that FatPig will never win or lose. We call it a draw game.
You are supposed to write a program to tell FatPig the result of the game induced by the initial deck cards.
Input
Each input set consists of a sequence of 52 integers representing the card value (King will be represent by 13, Queen by 12, and Jack 11) of the initial deck of the game starting from the top of the deck. Input is terminated by a single zero.
NOTE: FatPig is so special that you should not assume that in his set of cards there are exactly 4 cards of the same face value.
Output
For each set of input, print the result of the game as follows:
1. If FatPig wins the game, print information "FatPig will win the game in turn *." The "*" should be replaced by the turn FatPig wins the game. NOTE: If one card is dealt out from the deck, we call it one turn.
2. If FatPig loses the game, print information "FatPig will lose the game in turn *." The "*" should also be replaced by the turn FatPig dealing out the last card on the deck.
3. If FatPig will never win or lose, just print the message "A draw game." If we can't determine one FatPig's success in 500 turns, we think that it is a draw game.
Results should be printed without quotation marks.
Sample Input
1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 0
Sample Output
FatPig will lose the game in turn 52. FatPig will win the game in turn 14.Submit
Source: ZOJ Monthly, December 2004