题目描述
Problem Description
Long ago, in a distant land inhabited only by math students, Iva and Vedran were discussing a special type of sentence. In these sentences, exactly one word represents a number, and this number equals the total number of letters in the sentence. For example, This sentence has thirtyone letters. and Blah Blah seventeen.
Jurica overheard his friends' conversation and decided to impress them with his vast collection of special sentences. He rushed home and wrote a program that, given a sentence, finds the smallest number that can be inserted to make the sentence special.
Unfortunately, his computer broke down, and now he needs your help. Write a program to assist Jurica!
Additional notes:
- The sentence format is: $\textit{word}_1~\textit{word}_2~\textit{word}_3~\cdots~\textit{word}_{n-1}~\textit{word}_n$. Among these $n$ words, exactly one is
$`, representing the placeholder for a numeric word. For example, `this sentence has thirtyone letters` will become `this sentence has $ letters. - The words representing numbers follow these rules:
- For integers from $1$ to $19$, the words are
one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen, andnineteen. - For multiples of ten from $20$ to $90$, the words are
twenty,thirty,forty,fifty,sixty,seventy,eighty, andninety. - For multiples of one hundred from $100$ to $900$, the words are
onehundred,twohundred,threehundred,fourhundred,fivehundred,sixhundred,sevenhundred,eighthundred, andninehundred. - For other two-digit numbers, the word starts with the largest multiple of ten not exceeding the number, followed by the word for the units digit. For example, the word for $68$ is
sixtyeight. - For other three-digit numbers, the word starts with the largest multiple of one hundred not exceeding the number, followed by the word for the last two digits (following the previous rules). For example, the words for $319$, $530$, and $971$ are
threehundrednineteen,fivehundredthirty, andninehundredseventyone, respectively.
- For integers from $1$ to $19$, the words are
Input Format
The first line contains an integer $n$, the number of words in the sentence.
The next $n$ lines each contain a string, representing all the words in the sentence. Exactly one of these words is $.
Output Format
Output one line with $n$ strings, representing the sentence with $ replaced by the word for the smallest number that makes the sentence special.
Sample Input and Output
Sample Input #1
5
this
sentence
has
$
letters
Sample Output #1
this sentence has thirtyone letters
Sample Input #2
7
$
is
the
number
of
letters
here
Sample Output #2
thirty is the number of letters here
Sample Input #3
5
the
letters
are
$
potato
Sample Output #3
the letters are twentynine potato
Notes/Hints
[Sample 2 Explanation]
Inserting the word thirty for `$` results in a total letter count of $6+2+3+6+2+7+4=30$.
[Sample 3 Explanation]
Note that the sentences in this problem may not adhere to English grammar rules.
[Data Range and Constraints]
This problem is bundled with subtasks. The scores and special constraints for each subtask are as follows:
- Subtask 1 (40 pts): The number represented by the word inserted for `$` does not exceed $50$.
- Subtask 2 (60 pts): No special constraints.
For all data, $1 \leqslant n \leqslant 20$, and the number represented by the word inserted for `$` does not exceed $1000$.
[Problem Source]
This problem is from COCI 2013-2014 CONTEST 3 T3 REČENICE, configured according to the original problem data, with a full score of $100$ points.
Provided by Eason_AC for translation and arrangement.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分