UVa 10978

From Algorithmist
Jump to navigation Jump to search

10978 - Let's Play Magic[edit]

Summary[edit]

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[edit]

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

Input[edit]

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[edit]

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

Implementations[edit]