#P8243. [COCI 2013/2014 #3] REČENICE
[COCI 2013/2014 #3] REČENICE
Problem Description
A long time ago, in a distant country where only math students lived, Iva and Vedran were discussing a special kind of sentence. In these sentences, exactly one word represents a number, and that number equals the total number of letters in the sentence. For example, This sentence has thirtyone letters. and Blah Blah seventeen.
Jurica accidentally overheard his friends’ conversation and decided to impress them with the many special sentences he had memorized. He hurried 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, and now he needs your help. Write a program to help Jurica!
Here are some additional notes:
- The sentence has the form: $\textit{word}_1~\textit{word}_2~\textit{word}_3~\cdots~\textit{word}_{n-1}~\textit{word}_n$. Among these words, exactly one is
$, which marks the place where the number word should be filled in. For example,this sentence has thirtyone letterswould becomethis sentence has $ letters. - The words used to represent numbers follow these rules:
- For all integers from to , the words representing them in increasing order are
one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen, andnineteen. - For all multiples of ten from to , the words representing them in increasing order are
twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety. - For all multiples of one hundred from to , the words representing them in increasing order are
onehundred,twohundred,threehundred,fourhundred,fivehundred,sixhundred,sevenhundred,eighthundred,ninehundred. - For all other two-digit numbers, first put the word for the largest multiple of ten not exceeding the number, then concatenate the word for the units digit. For example, the word for the integer is
sixtyeight. - For all other three-digit numbers, first put the word for the largest multiple of one hundred not exceeding the number, then concatenate the word for the last two digits (following the previous rules). For example, the words for the integers are
threehundrednineteen,fivehundredthirty, andninehundredseventyone.
- For all integers from to , the words representing them in increasing order are
Input Format
The first line contains an integer , the number of words in the sentence.
Then follow lines, each containing a string, representing all the words of the sentence. It is guaranteed that $ appears exactly once among them.
Output Format
Output one line with strings, representing the sentence after replacing $ with the word for the smallest number that makes the sentence special.
5
this
sentence
has
$
letters
this sentence has thirtyone letters
7
$
is
the
number
of
letters
here
thirty is the number of letters here
5
the
letters
are
$
potato
the letters are twentynine potato
Hint
[Explanation of Sample 2]
Fill $ with the word thirty, which represents the integer . Then the total number of letters in all words is .
[Explanation of Sample 3]
Note that the sentence in this problem may not satisfy English grammar rules.
[Constraints]
This problem uses bundled testdata. The score and special limits of each subtask are as follows:
- Subtask 1 (40 pts): the number represented by the word filled into
$does not exceed . - Subtask 2 (60 pts): no special limits.
For all testdata, , and the number represented by the word filled into $ is less than .
[Source]
This problem is from COCI 2013-2014 CONTEST 3 T3 REČENICE, using the original data configuration, with a full score of points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5