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.

Since there will always be an existing solution less than 1000, we can simply try and put each number from the interval [1, 999] in the sentence and check whether it is the possible solution. For a sentence with the number x in it to be valid, the following condition must be met:

length of the name of number x + sum of word length in the sentence = x

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, special[], tens[], hundreds[]
  • the array special is going to consist of names of numbers 1 to 19, e.g. special[11] is going to be eleven
  • the array tens is going to consist of names of tens, e.g. tens[7] is going to be seventy
  • identically, the array hundreds is going to consist of names of hundreds, e.g. hundreds[3] 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

There are no comments at the moment.