[Python] ผำควนโดยพอนไธ / Thai Spoonerism with Python

จากโจทย์ที่มีโกนพาสเบ็นหนด ว่วยด้าการสร้างควนผำ http://www.pagist.info/7331317

ผึงจมดำไถ้แปรมโกผำควนข้ามึนเป็นภาษาพอนไธ

 
juannam = len
jemnuantam = int
rut_inpaw = raw_input
 
def tamkad(kam):
    sara = {'a','e','i','o','u'}
    for akkirata in range(juannam(kam)):
        if kam [akkirata]  in sara:
            return (kam [:akkirata] ,kam [akkirata:] )
    return kam
 
def pangpayuan(paekyangra, pangyangla):
    (payanchanaektonpayangra, sianglangpaekyangra) = tamkad(paekyangra)
    (payanchanangtonpayangla, sianglangpangyangla) = tamkad(pangyangla)
    return (payanchanaektonpayangra+sianglangpangyangla, payanchanangtonpayangla+sianglangpaekyangra)
 
def pamkuan(kam):
    pangya = kam.split()
    if juannam(pangya) < 2: #mai tueng sung kom pai mai duan
        return kam
    lamdabkaektipuankamram, lamdabkangtipuankamram = (juannam(pangya)/2-1, juannam(pangya)-1)
    (pangya [lamdabkaektipuankamram] , pangya [lamdabkangtipuankamram] ) = pangpayuan(pangya [lamdabkaektipuankamram] , pangya [lamdabkangtipuankamram] )
    return ' '.join(pangya)
 
def main():
    jamnuankam = jemnuantam(rut_inpaw())
    for kitam in range(jamnuankam):
        print pamkuan(rut_inpaw())
    return
 
main()
 

ป.ล. มันยากอีตรงผวนโค้ดนี่แหละ = =”

Leave a Reply