취미생활/CheckIO

[checkIO]Home 11.Bird Language

우주먼지의하루 2020. 2. 17. 16:09
728x90

Stephan has a friend who happens to be a little mechbird. Recently, he was trying to teach it how to speak basic language. Today the bird spoke its first word: "hieeelalaooo". This sounds a lot like "hello", but with too many vowels. Stephan asked Nikola for help and he helped to examine how the bird changes words. With the information they discovered, we should help them to make a translation module.

The bird converts words by two rules:

- after each consonant letter the bird appends a random vowel letter (l ⇒ la or le);

- after each vowel letter the bird appends two of the same letter (a ⇒ aaa);

Vowels letters == "aeiouy".

You are given an ornithological phrase as several words which are separated by white-spaces (each pair of words by one whitespace). The bird does not know how to punctuate its phrases and only speaks words as letters. All words are given in lowercase. You should translate this phrase from the bird language to something more unerstandable.

Input: A bird phrase as a string.

Output: The translation as a string.

Example:

translate("hieeelalaooo") == "hello"

translate("hoooowe yyyooouuu duoooiiine") == "how you doin"

translate("aaa bo cy da eee fe") == "a b c d e f"

translate("sooooso aaaaaaaaa") == "sos aaa"

*새는 자음 뒤에 임의의 모음을 붙인다

*모음을 쓰는 경우 세개를 더 붙인다

*자음 뒤 하나의 모음은 해석에 필요 없는 모음이다.

 

- 풀이

 

VOWELS = "aeiouy"

def translate(phrase):
    new_list = []
    i = 0

    while i < len(phrase):
        new_list.append(phrase[i])
        if phrase[i] in VOWELS:
            i += 3
        elif phrase[i] == ' ':
            i += 1
        else:
            i += 2
    return ''.join(new_list)
반응형

'취미생활 > CheckIO' 카테고리의 다른 글

[checkIO]Element 01.Say Hi  (0) 2020.02.21
[checkIO]Home 12.Xs and Os Referee  (0) 2020.02.19
[checkIO]Home 10.Sun Angle  (0) 2020.02.17
[checkIO]Home 08. Long Repeat  (0) 2020.02.16
[checkIO]Home 07.Flatten a List  (0) 2020.02.16