UVa 10978 - Let's Play Magic!

10978 - Let's Play Magic

 * http://acm.uva.es/p/v109/10978.html

Summary
N cards are arranged in a circle. Starting from a certain card, the magician counts cards in clockwise direction and spelling N words. When the last letter of a word is pronounced, he turns over the card and removes it from the circle.

Given the sequence of words, and the order, in which the cards are removed, find the initial arrangement of cards in the circle.

Explanation
Simply simulate the magician's actions and recover the arrangement of cards.

Input
13 AS ACE 2S TWO 3S THREE 4C FOUR 5C FIVE 6C SIX 7D SEVEN 8D EIGHT 9D NINE TH TEN JH JACK QH QUEEN KH KING 0

Output
QH 4C AS 8D KH 2S 7D 5C TH JH 3S 6C 9D

Implementations
C++