PROG0464 - Namewords

no tags 

What is the link between the following words:

beaned, dotted, granted, herbal, homered, jackal, leeward, royal, patron, victim, Victorian

Every word can be split in two parts that are each a first name: Bea and Ned, Dot and Ted, …

Assignment

Write a function nameword to which a word (string) and a collection of first names (strings) must be given. Every first name consist of an uppercase letter, followed by zero or more lowercase letters. If the word can be composed of two first names of the given collection (regardless of the use of uppercase and lowercase letters in the word), the function must print a string with both first names, separated by a hyphen. The first names should both start with an uppercase letter, followed by a sequence of lowercase letters. If the word can not be composed with two first names from the collection, the function must print an empty string.

Note: If there are multiple ways the given word can be composed of first names from the given collection, the function must print the combination of which the first name is the shortest.

Example

>>> firstnames = {'Vic', 'Ian', 'Pat', 'Ron', 'Roy', 'Al', 'Tim', 'Jack'}
>>> nameword('patron', firstnames)
'Pat-Ron'
>>> nameword('Victorian', firstnames)
''
>>> nameword('victim', firstnames)
'Vic-Tim'
>>> nameword('JACKAL', firstnames)
'Jack-Al'
>>> nameword('royal', firstnames)
'Roy-Al'
>>> nameword('herbal', firstnames)
''

Wat is het verband tussen de volgende woorden:

beaned, dotted, granted, herbal, homered, jackal, leeward, royal, patron, victim, Victorian

Elk woord kan gesplitst worden in twee delen die allebei voornamen zijn: Bea en Ned, Dot en Ted, …

Opgave

Schrijf een functie voornaamwoord waaraan een woord (string) en een verzameling voornamen (strings) moeten doorgegeven worden. Elke voornaam bestaat hierbij uit een hoofdletter, gevolgd door nul of meer kleine letters. Indien het woord kan samengesteld worden uit twee voornamen van de gegeven verzameling (ongeacht het gebruik van hoofdletters en kleine letters in het woord), dan moet de functie een string teruggeven met daarin die twee voornamen, gescheiden door een koppelteken. De voornamen moeten hierbij ook beginnen met een hoofdletter, gevolgd door een reeks kleine letters. Indien het woord niet kan samengesteld worden uit twee voornamen van de gegeven verzameling, dan moet de functie de lege string teruggeven.

Opmerking: Indien het gegeven woord op meerdere manieren kan opgesplitst worden in voornamen uit de gegeven verzameling, dan moet de functie de combinatie teruggeven waarvan de eerste voornaam het kortst is.

Voorbeeld

>>> voornamen = {'Vic', 'Ian', 'Pat', 'Ron', 'Roy', 'Al', 'Tim', 'Jack'}
>>> voornaamwoord('patron', voornamen)
'Pat-Ron'
>>> voornaamwoord('Victorian', voornamen)
''
>>> voornaamwoord('victim', voornamen)
'Vic-Tim'
>>> voornaamwoord('JACKAL', voornamen)
'Jack-Al'
>>> voornaamwoord('royal', voornamen)
'Roy-Al'
>>> voornaamwoord('herbal', voornamen)
''


Added by:Peter Dawyndt
Date:2014-04-07
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None