티스토리 뷰

python lecture/algorism

[edu] Wepe speapeak p

burningrizen 2018. 10. 2. 01:44

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 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
댓글