본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 62

반응형

Q>

Stephan has a friend who happens to be a little mechbird.

(Stephan에는 작은 mechbird 인 우연히 친구가있다)

Recently, he was trying to teach it how to speak basic language.

(최근 그는 기본 언어를 말하는 법을 가르치려고 노력하고있었습니다.)

Today the bird spoke its first word: "hieeelalaooo".

(오늘 새는 그것의 첫번째 낱말을 말했다 : "hieeelalaooo".)

This sounds a lot like "hello", but with too many vowels.

(이것은 "hello"와 비슷하지만 모음이 너무 많습니다.)

Stephan asked Nikola for help and he helped to examine how the bird changes words.

(Stephan은 Nikola에게 도움을 요청했고 그는 새가 단어를 어떻게 바꾸는 지 검사하는 일을 도왔습니다.)

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);(각 모음 글자 뒤에 새가 같은 글자 2개를 추가합니다)

Vowels letters == "aeiouy".

(모음 글자 == "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 understandable.

(조류 문구에서이 문구를 좀 더 이해하기 쉬운 것으로 번역해야합니다.)

 

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"

 

How it is used: This a similar cipher to those used by children when they invent their own "bird" language.

                     (어린이가 자신의 "새"언어를 만들 때 사용하는 암호와 비슷한 암호입니다.)

                     Now you will be ready to crack the code.

                     (이제 코드를 해독 할 준비가되었습니다.)

 

Precondition: 

re.match("\A([a-z]+\ ?)+(?<!\ )\Z", phrase)
A phrase always has the translation.

(어구에는 항상 번역이 있습니다.)

 

A>

# 정규표현식
import re

VOWELS = "aeiouy"

# \1 정규표현식 재참조부 활용
# 정규표현식으로 중복 문자 제거 방법
# \w 문자+숫자(alphanumeric)와 매치
def translate(phrase):
    return re.sub(r'(\w)\1?.', r'\1', phrase)

if __name__ == '__main__':
    print("Example:")
    print(translate("hieeelalaooo"))

    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert translate("hieeelalaooo") == "hello", "Hi!"
    assert translate("hoooowe yyyooouuu duoooiiine") == "how you doin", "Joey?"
    assert translate("aaa bo cy da eee fe") == "a b c d e f", "Alphabet"
    assert translate("sooooso aaaaaaaaa") == "sos aaa", "Mayday, mayday"
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

 

O>

Example:
hello
Coding complete? Click 'Check' to review your tests and earn cool rewards!

Process finished with exit code 0

 

S>

https://py.checkio.org/

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 64  (0) 2019.06.14
Python Learn the basics Quiz 63  (0) 2019.06.14
Python Learn the basics Quiz 61  (0) 2019.06.12
Python Learn the basics Quiz 60  (0) 2019.06.12
Python Learn the basics Quiz 59  (0) 2019.06.12