Website
AskDev.ru holds a competition in sports programming with prizes in the style of code golf (winning the shortest program in length).
Competitive task: write a program for the game "in the city."
The input is an array of the form
')
[Kaliningrad, Vologda, Almaty, Dmitrov, Arkhangelsk, Tobolsk, Krakow]
At the exit.
[Arkhangelsk, Krakow, Vologda, Almaty, Tobolsk, Kaliningrad, Dmitrov]
Please take into account that there are no cities with the letter in this list, therefore the search goes on according to the previous letter.
Important: the letter Y in the example above is excluded, not because it is bad, but because there are no cities in the list that begin with Y. You can use the penultimate letter only if there are no words starting with the last letter.
Example:
source array
[Kaliningrad, Vologda, Dalmatovo, Dmitrov, Arkhangelsk, Vladivostok, Krakow]
wrong decision, Vologda-Dmitrov crossing is not allowed
[Arkhangelsk, Kaliningrad, Dalmatovo, Vologda, Dmitrov, Vladivostok, Krakow]
correct solution
[Dmitrov, Vologda, Arkhangelsk, Kaliningrad, Dalmatovo, Vladivostok, Krakow]
The solution will be tested on several examples in which there may be other "bad" letters. Write code universally.
Wins the one who spends fewer characters to solve the problem.
Notes
1. The most important thing is that the code be as short as possible, that is, you can call the variables a, b, c, write in one line, remove all extra spaces, brackets, comments, etc. You can publish two variants of the code, competitive and expanded, for clarity. Only competitive is taken into account.
The I / O code and module connection code is not taken into account when counting characters. Line breaks count as one character.
2. You can use only standard modules that come with the language.
3. The I / O code and the connection of modules are not taken into account when calculating the results.
4. If you are using an exotic programming language, tell the organizers where to download the compiler.
5. The name of the city always begins with a capital letter.
6. The sample will be composed so that the solution always exists.
Summing up and prizes
The results are summarized on May 25, at 23:59 Moscow time.
The prize is an external hard drive
A-Data Sport SH93 500GB .
Read the full terms of the contest and send your solution