티스토리 뷰
The inhabitants on planet P people speak a strange language, called language P. For us, this language is not so difficult to learn. After all, it is very similar to plain English, but every group of vowels is followed by a letter p and a repetition of the same group of vowels. A groups of vowels is either a sequence of one or more consecutive vowels (a,e,i,o and u) or the combination ij. As such, the word cuckoo is translated into language P as cupuckoopoo.
Assignment
Write a program that can translate words and sentences in language P into plain English.
Input
A single line containing a word or a sentence in language P.
Output
A single line containing the input line translated into plain English.
Example
Input:
Grapandmapa Epevepe's cupuckoopoo clopock seepeems bropokepen.
Output:
Grandma Eve's cuckoo clock seems broken.
Example
Input:
Whepen thepe capat's apawapay, thepe mipicepe wipill plapay.
Output:
When the cat's away, the mice will play.
ver. 0.3
# vowel + p > vowel + p + vowel
# vowel + vowel + p > vowel + vowel + p + vowel + vowel
def check_vowel(char):
VOWELS = ['a', 'e', 'i', 'o', 'u']
for vowel in VOWELS:
if char.lower() == vowel:
return True
return False
def check_p(chars):
index_token = int(len(chars) / 2)
cond_token = chars[index_token] == 'p'
for i in range(index_token):
cond_vowel = chars[i].lower() == chars[i + index_token + 1].lower()
if cond_token and cond_vowel:
return True
return False
def get_issue_chars(chars, start, length):
issue_chars = list()
stop = start + length + 1
for i in range(start, stop):
issue_chars.append(chars[i])
return issue_chars
def get_index_remove(chars, cur, length):
indexes = list()
cond_p = check_p(get_issue_chars(chars, cur, length)) if cur + length < len(chars) else False
if cond_p:
half = int(length / 2)
index_token = cur + half
stop = cur + length + 1
for i in range(index_token, stop):
indexes.append(i)
return indexes
def extract_words(chars, indexes):
result = ""
for i in range(len(chars)):
if not i in indexes:
result += chars[i]
return result
def trans_p(chars):
indexes = list()
for i in range(len(chars)):
cond_vowel = check_vowel(chars[i])
if cond_vowel:
cond_vowel_double = i + 1 < len(chars) and check_vowel(chars[i + 1])
if cond_vowel_double:
indexes.extend(get_index_remove(chars, i, 4))
else:
indexes.extend(get_index_remove(chars, i, 2))
print(extract_words(chars, indexes))
trans_p(str(input()))
'python lecture > algorism' 카테고리의 다른 글
[edu] Corkscrew (0) | 2018.10.04 |
---|---|
[eud] Cowsay (0) | 2018.10.02 |
[edu] Pythagorean triples (0) | 2018.10.02 |
[edu] Monkeys and coconuts (0) | 2018.10.02 |
[edu] 성능 시작측정 코드(decorator, prime, 소수) (0) | 2018.08.27 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Python
- 장고
- wsgi
- 모바일 테마 적용
- 이미지 비교
- gitignore
- 장고 플러스친구 자동응답
- 문서 비교
- 파이썬 강좌
- pycrypto
- gitlab
- django chatbot
- 면접정답
- 장고 카톡 자동응답
- virtualenv
- chatbot
- 문과 코딩
- 플러스친구 자동응답
- 파이썬 독학
- 파이썬
- PuTTYGen
- admin.py
- GIT
- 모바일 스킨 적용
- 파이썬 입문
- django
- 면접답변
- 파이썬 프로그래밍
- 엑셀 비교
- Tistory
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
글 보관함