commit c9be15672ccf24da270d6c2db7031d8cd5ef98a1 Author: allem Date: Mon Jan 29 16:14:37 2018 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32f1c9d --- /dev/null +++ b/.gitignore @@ -0,0 +1,108 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +.static_storage/ +.media/ +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +.idea/ \ No newline at end of file diff --git a/haiku_sol.py b/haiku_sol.py new file mode 100644 index 0000000..4ab8046 --- /dev/null +++ b/haiku_sol.py @@ -0,0 +1,40 @@ +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()) diff --git a/icpc_test.py b/icpc_test.py new file mode 100644 index 0000000..33ba62f --- /dev/null +++ b/icpc_test.py @@ -0,0 +1,31 @@ +import glob, sys, subprocess + +_, src, test, t = sys.argv + +ig = glob.glob(f'test/{test}/*.in') +og = glob.glob(f'test/{test}/*.ans') + +print(test, len(ig), 'tests') + +for ifn, ofn in zip(ig, og): + with open(ifn) as fi, open(ofn) as fx: + try: + o = subprocess.check_output(['python', src], + stdin=fi, stderr=subprocess.STDOUT, + timeout=float(t)) + except subprocess.CalledProcessError as e: + o = e.output + except subprocess.TimeoutExpired: + o = b'TIMED OUT' + + o = o.decode('utf-8').strip().replace('\r\n', '\n') + x = fx.read().strip().replace('\r\n', '\n') + + if o != x: + print(ifn, 'expected:', x, 'got:', o, '=' * 50, sep='\n') + +# run this with arguments: +#