Under construction

Still being built. Things may change

Estonian Number Words Sort

Time limit1sMemory limit1024 MB

Summary
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 (…\ldots, 100100, 1010, 11). If a place holds only 00, that place is not written.
  • Places are grouped in steps of 1 0001\,000 (…\ldots, 1 000 0001\,000\,000, 1 0001\,000, 11). 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.

NumberWordsNumberWords
00null9090üheksakümmend
11üks100100sada, ükssada
22kaks200200kakssada
33kolm......
44neli900900üheksasada
55viis1 0001\,000tuhat, üks tuhat
66kuus2 0002\,000kaks tuhat
77seitse......
88kaheksa100 000100\,000sada tuhat, ükssada tuhat
99üheksa106=1 000 00010^6 = 1\,000\,000miljon, üks miljon
1010kümme2 000 0002\,000\,000kaks miljonit
1111üksteist3 000 0003\,000\,000kolm miljonit
1212kaksteist109=1 000 000 00010^9 = 1\,000\,000\,000miljard, üks miljard
......2 000 000 0002\,000\,000\,000kaks miljardit
1919üheksateist3 000 000 0003\,000\,000\,000kolm miljardit
2020kakskümmend−2 510-2\,510miinus kaks tuhat viissada kümme
2121kakskümmend üks−100-100miinus sada, miinus ükssada
2222kakskümmend kaks1 1111\,111tuhat ükssada üksteist, üks tuhat ükssada üksteist
......2 2042\,204kaks tuhat kakssada neli
3030kolmkümmend2 345 000 4122\,345\,000\,412kaks miljardit kolmsada nelikümmend viis miljonit nelisada kaksteist
3131kolmkümmend üks

Input

The first line contains the number of values NN (2≤N≤1042 \le N \le 10^4). Each of the next NN lines contains one integer written fully in words, following the rules above. Every letter ü in the input is replaced by u. The value AiA_i on each line is within the range of a 32-bit signed integer (−231≤Ai<231-2^{31} \le A_i < 2^{31}).

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.

Examples1

  1. Example 1

    Input
    5
    kaks tuhat kakssada neli
    viisteist
    miinus kaks tuhat viissada kumme
    tuhat ukssada uksteist
    kolm
    
    Expected output
    miinus kaks tuhat viissada kumme
    kolm
    viisteist
    tuhat ukssada uksteist
    kaks tuhat kakssada neli