Editorial for COCI '13 Contest 3 #3 Rečenice
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Since there will always be an existing solution less than , we can simply try and put each number from the interval in the sentence and check whether it is the possible solution. For a sentence with the number in it to be valid, the following condition must be met:
length of the name of number sum of word length in the sentence
Now the only problem is to create a function which will determine the names of numbers. We can do this in the following way:
- create three arrays, , ,
- the array is going to consist of names of numbers to , e.g. is going to be
eleven
- the array is going to consist of names of tens, e.g. is going to be
seventy
- identically, the array is going to consist of names of hundreds, e.g. is going to be
threehundred
- now we implement naming the numbers as described in the task
Pseudocode:
name(x)
answer = ''
if the hundreds' digit of x is not 0:
answer = answer + hundreds[hundreds' digit of x]
remove the hundreds' digit from x
if x is from the interval [1, 19]:
answer = answer + special[x]
else:
if the tens' digit of x is not 0:
answer = answer + tens[tens' digit of x]
if the single digit of x is not 0:
answer = answer + single[single digit of x]
Comments