Pig Latin

“Pig Latin”是一个英语儿童文字改写游戏,整个游戏遵从下述规则:

(1). 元音字母是‘a’、‘e’、‘i’、‘o’、‘u’。字母‘y’在不是第一个字母的情况下,也被视作元音字母。其他字母均为辅音字母。例如,单词“yearly”有三个元音字母(分别为‘e’、‘a’和最后一个‘y’)和三个辅音字母(第一个‘y’、‘r’和‘l’)。

(2). 如果英文单词以元音字母开始,则在单词末尾加入“hay”后得到“Pig Latin”对应单词。例如,“ask”变为“askhay”,“use”变为“usehay”。

(3). 如果英文单词以‘q’字母开始,并且后面有个字母‘u’,将“qu”移动到单词末尾加入“ay”后得到“Pig Latin”对应单词。例如,“quiet”变为“ietquay”,“quay”变为“ayquay”。

(4). 如果英文单词以辅音字母开始,所有连续的辅音字母一起移动到单词末尾加入“ay”后得到“Pig Latin”对应单词。例如,“tomato”变为“omatotay”, “school” 变为“oolschay”,“you” 变为“ouyay”,“my” 变为“ymay ”,“ssssh” 变为“sssshay”。

(5). 如果英文单词中有大写字母,必须所有字母均转换为小写。

输入格式:
一系列单词,单词之间使用空格分隔。

输出格式:
按照以上规则转化每个单词,单词之间使用空格分隔。

输入样例:
Welcome to the Python world Are you ready

输出样例:
elcomeway otay ethay ythonpay orldway arehay ouyay eadyray

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
# import math
# import datetime
# import sys

# from PyQt4.QtCore import *
# from PyQt4.QtGui import *

# import numpy as np
# import matplotlib.pyplot as plt
# import copy

result = ''

s = raw_input()
s = s.split()
# print s
# print s[0]
# l1 = ['a', 'e', 'i', 'o', 'u']

for word in s:
    word = word.lower()
    # print word
    if re.match('[aeiou]', word):
        result = result + word + 'hay' + ' '
        # print word + 'hay'
    elif re.match('qu', word):
        # print word[2:] + 'quay'
        result = result + word[2:] + 'quay' + ' '
    # else:
    #     for index, alph in enumerate(word):
    #         if word[0] == 'y':
    #             if re.search('[aeiou]', alph):
    #              # word = word[index+1:] + word[:index+1] + 'ay'
    #              # print word
    #                 break
    #         else:
    #             if re.search('[aeiouy]', alph):
    #                 break
    #     word = word[index:] + word[:index] + 'ay'
    #     print word

    elif not re.search('[aeiouy]', word):
        # print word + 'ay'
        result = result + word + 'ay' + ' '
    else:
        for index, alph in enumerate(word[1:]):

            if re.search('[aeiouy]', alph):
             # word = word[index+1:] + word[:index+1] + 'ay'
             # print word
                    break
            # else:
            #     if re.search('[aeiouy]', alph):
            #         break
        # print word[index+1:] + word[:index+1] + 'ay'
        result = result + word[index+1:] + word[:index+1] + 'ay' + ' '


print result[:-1]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值