A confused Dutchman trying to speak English could say “I am in the war”, even though there is no hostile activity going on. The confusion here is that the English sentence “I am confused” is translated in Dutch as “Ik ben in de war”, which is phonetically (“sounding”) quite close to the first sentence. Such confusion leads to much enjoyment, but can complicate matters a bit.
As a Dutch company and computer programmers we want to automate the process of translating. However, our dictionary unfortunately has some Dunglish translations in there. Luckily, for whatever reason, the creators of the dictionary have indicated for every word if it is a correct translation or an incorrect "Dunglish" one.
The goal of the exercise is to display, for a given sentence, how many ways we can translate it, and if there is only one translation output for that translation.Input:
Each time your program runs it has to try to translate one sentence. The first line of input is the sentence you have to translate. This sentence will consist of between 1 and 20 words separated by spaces, each word will be between 1 and 20 lowercase letters.
After this first line you will receive the dictionary. This will consist of multiple lines, each line being an entry in the dictionary. Each entry contains three words separated by spaces, the first word is the Dutch word that the translation is for, the second word is the English translation, the third and final word is either "english
" or "dunglish
" depending on if this entry is a correct translation, or a Dunglish one.
It is guaranteed that each word of the sentence that should be translated will have at least one translation, and no more than 8.Output:
The expected output of your program is depended on the amount of possible translations. If there is only one possible translation you should output that translation, followed by either "english
" if it is a correct English translation according to the given dictionary or "dunglish
" if it is a Dunglish translation.
If you can translate the given sentence in multiple ways you should output the amount of possible translations, and the amount of which are "english
goedendag hello english
sigcse sigcse english
This is a simple example. As every word can only be translated one way it is clear that there is one translation only. As every translation is correct it is also clear that the resulting translation is English.Example 2:
Input:als mollen mollen mollen mollen mollen mollen
als when english
mollen moles english
mollen destroy english
mollen mills dunglish
There are multiple translations for one of the words in the sentence, this means that we will always be able to create multiple translations. So our objective is to calculate the amount of possible translations. The amount of total translations is easily calculated by multiplying the amount of possible translations for each word. So in our case that is 1 * 3 * 3 * 3 * 3 * 3 * 3 = 3^6 = 729
. To get the correct translations we do the same thing, but now we multiply the amount of possible correct translations: 1 * 2 * 2 * 2 * 2 * 2 * 2 = 2^6 = 64
Input:de zuigers zijn buiten werking
zijn are english
banaan banana english
de the english
zuigers suckers dunglish
buiten out english
werking working dunglish
Output:the suckers are out working
There is exactly one translation for every word in the sentence, this means that we are only able to create one translation. So our objective is to find that translation. As we see that one of the translations is Dunglish we know that our resulting translation is also Dunglish.Challenge from Northwestern European Regional Contest 2017.
A template to do input handling and output printing is already available within the CodeGrade editor, all you have to do for this puzzle is create the short algorithm to get to the correct output. You have to fill in the #TODO sections in the count_possible_translations and print_any_translation functions. Press the Hand In button to check your solution as many times as you want, press the Edit button to go back to editing!