Estonian Number Words Sort
Time limit1sMemory limit1024 MB
Sort N integers given as Estonian number words, where the words are first converted to values and then ordered in non-decreasing order.
- Level
Medium5 of 10
- Topics
- String, Sorting, Implementation
- Solved
- No attempts yet
Problem
Data is not always given in a form that is easy to process. What happens when you have to work with values written or spoken in human language? This problem sorts integers written in Estonian.
Converting numbers requires some spelling rules. The basic rules are:
- Words ending in -teist, -kümmend, and -sada are written together with the number word before them. All other number words are written separately (following an Estonian grammar reference).
- Numbers are mostly written in descending order of place value (, , , ). If a place holds only , that place is not written.
- Places are grouped in steps of (, , , ). The name of each group ('miljon', 'tuhat') is written only once.
The table below covers the numbers needed to read Estonian numbers in the given range. Parallel forms are separated by commas. Other parallel forms are in use, but this problem keeps only the forms shown here.
Input
The first line contains the number of values (). Each of the next lines contains one integer written fully in words, following the rules above. Every letter ü in the input is replaced by u. The value on each line is within the range of a 32-bit signed integer ().
Output
Print the numbers written in words in non-decreasing order, one per line. Each printed line must match the corresponding input line exactly. Lines with equal values may appear in any order.