University of Lethbridge - Mathematics & Computer Science

Problem #3 Romulan Spelling

Romulans use a language that can be approximated with the English alphabet and normal punctuation marks. Their spelling rules are even stranger than English, however. In particular, they have a rule that states:

  G before P except after E or when pronounced X as in npgukbor or wpguk.
Operationally, you can detect the X pronounciation by the string PGUK appearing in the word. Also, the Romulan rules for capitalization are different from ours, so capital letters can appear anywhere in a word.

Given a file containing lines of Romulan text, you are to output the text with spelling corrected according to the G before P except after E rule given above. No input line will contain more than 80 characters including spaces.

Consider the following quote:

"I received the wierd piece of pie from my neighbor sam who in turn recieved 
the weird peice of pei from his nieghbor harry," 
The romulan translation (stored in the input file romulan.dat) might well be:
"I rpepgvpd tKp wgprd tgpep of tgp from my npgukbor sam wKo gn turn rpegpvpd 
tKp wpgrd tpgep of tpg from Kgs ngpukbor Karry,"
And the output (saved in the output file romulan.out) would be :
"I rpepgvpd tKp wgprd tgpep of tgp from my npgukbor sam wKo gn turn rpepgvpd 
tKp wgprd tgpep of tgp from Kgs npgukbor Karry,"


Original problem: Rocky Mountain Region ACM contest, 1990