This repository has been archived on 2026-05-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files
ICPC-2017/haiku_sol.py
2018-01-29 16:14:37 -05:00

41 lines
847 B
Python

import re
line = input().strip()
sylcounts = [5, 7, 5]
words = re.findall('[a-zA-Z]+', line)
originals = line.split()
final = ''
for word, original in zip(words, originals):
word = word.lower().replace('qu', 'q')
word = re.sub('y[aoeui]', 'b', word)
if re.match('.*e$', word) and not re.match('.*[^aoeuiy]le$', word):
word = word[:-1]
if re.match('.*es$', word) and not re.match('.*[^aoeuiy][^aoeuiy]es', word):
word = word[:-2]
word = re.sub('[aoeuiy]+', 'A', word)
syllables = word.count('A') or 1
sylcounts[0] -= syllables
final += original + ' '
if sylcounts[0] == 0:
del sylcounts[0]
final = final[:-1] + '\n'
continue
if sylcounts[0] < 0:
final = line
sylcounts = []
break
if sylcounts:
final = line
print(final.strip())