Home‎ > ‎ProgComp‎ > ‎ProgComp 2015‎ > ‎

Task 2. Goonerism Spenerator

Task 2. Goonerism Spenerator

Available Marks: 9

Spoonerisms are phrases where the non-vowel prefixes of non-trivial words are mixed up. For example, "a crushing blow" might become "a blushing crow". They are named after the Reverend William Spooner (1844–1930), an Oxford lecturer whose tongue (it is said) could never keep up with his thought processes.

The spoonerism generator to be written to solve this task must follow certain rules.

  1. Each input phrase consists of words in lower case separated by a space.
  2. Trivial words are unchanged (see list below).
  3. Words starting with a vowel (a e i o u) are unchanged.
  4. The prefix of each word starting with a non-vowel replaces the prefix in the next word to its right that has a prefix, with the last prefix replacing the first. A prefix consists either of all initial non-vowels or the special prefix "qu".

For the purposes of this task, trivial words are words with 2 or fewer letters, or any of the following.

for has have she that the this will with
"for", "has", "have", "she", "that", "the", "this", "will", "with"
The quoted list may be suitable to copy to your program.

Your task

Write a program that reads in phrases and displays the corresponding spoonerisms. The first line of input contains the number of phrases (up to 20). The remaining lines have one phrase each. Each phrase has between 1 and 25 words, and a total length of up to 100 characters.

Example

4
bouncing tree
a blushing crow
we will have the flags hung out
the three little pigs and the big bad wolf
produces...
trouncing bee
a crushing blow
we will have the hags flung out
the wee thrittle ligs and the pig bad bolf

Test data

Test your program using the following input text.

18
belly jeans
bat flattery
flutter by
pop corn
this is the fun part
my spoonerism generator
a lack of pies
go and take a shower
i hate with my mind
pain in the posterior
anthropomorphism 
hickory dickory dock
the rain in spain falls mainly on the plain
pack my box with frumpy dozen lusty jugs
strange women lying in ponds distributing swords is no basis for a system of government
this caged parrot is no more
the quick brown fox jumps over the lazy dog
back home after jiving she expired with quizzicality

You can obtain part marks for a limited solution, for example only swapping two word prefixes or not ignoring trivial words, but your program must at least correctly identify word prefixes.


Image source: Wikimedia, via telegraph.co.uk

Comments