|
The showdown
Thanks for the map you were able to easily find the room of the
terrorist leaders. The room is empty right now, however in a few hours
the Meeting will start, where every influential maffia leader will be
present. In the middle of the room there is a big table with 12 chairs.
The 4 corners of the table is marked differently, so the members of the
4 main terrorist clans know where they should sit. If the clan members
are not sitting in their usual place, then the ancient, suppressed
conflicts will break out and they get rid of each other. So your task
is to jumble the sitting list and "let the problem sort itself out".
Input
The input a single line, terminated by an end of line character.
The line contains 12 strings, separated by a single space
character. Each string is 5 character long and uses letters from
the english alphabet. The first letter of each word is a capital
letter, the rest are small letters.
Output
The output is a single line containing each of the 12 strings from the
input, separated by a single space character and ordered by the rules below.
Rules
- The table is a rectangle and on each side there are 2-2
chairs, and on each corner there are 1-1. The numbering of the
chairs starts with 1 on the "top left" corner and moves
clockwise by one until the 12th chair. So the 12th chair is directly below the 1st
one.
- The names in the output must follow this numbering, so the
first name in the output is the person sitting on chair 1, the
second name in the output is the person sitting on chair 2,
etc.
- The names in the input must be processed one by one from
left to right. The seating goes by the below rules:
- Those people whose name starts with one of the
"QUTHCRDMZ" characters must be seated as close to the top
left (1st) chair as possible.
- Those people whose name starts with one of the
"WEVOXING" characters must be seated as close to the top
right (4th) chair as possible.
- Those people whose name starts with one of the
"JFABKPLY" characters must be seated as close to the bottom
right (7th) chair as possible.
- Those people whose name starts with the
"S" character must be seated as close to the bottom
left (10th) chair as possible.
- Measuring the distance is simply done by "minimum how many
chairs are between me and my preferred corner?"
- If a person can be seated to more than one places, then
they prefer the one which is counter
clockwise to their preferred corner.
Summary: based on the above the idea of the
seating is the following: we try to seat everyone as close as
possible to their preferred corner. If the seat is taken, then we
find the first empty chair closest to that corner and seat the
person there. If there are two chairs of the same distance of the
corner, then we choose the one which is counter
clockwise to that corner (e.g. if someone prefers to sit
at the top right corner, so at chair 4, but this chair is taken,
but chairs 3 and 5 are empty, then since they are both 1 chair away
from the corner we choose 3, since that is the one counter clokwise
to 4).
Example
Explanation
Instead of a detailed explanation we just simply show the finished
seating order and show the order of the seating.
Teseb (5) Onets (7) Verap (3) Xenna (2)
Tpets (10) Ebyam (4)
Girnu (12) Ycuag (6)
Skcaw (8) Lizuf (11) Yrovi (9) Yojne (1)
|
|