Python 对联——文字竖向排版的实现

Python032

Python 对联——文字竖向排版的实现,第1张

今有如下对联,需按传统竖排版的来实现:

上联:眼观形色内无有

下联:耳听尘事心不知

横批:轻松自在

欲达到的排版效果:

 轻松自在 

耳眼

听观

尘形

事色

心内

不无

知有

输出效果:

# coding=utf-8

# using python2.7

def f(string):

    for i in string.decode('utf-8'):

        print i

f('哈哈123')

就把中文字符当作英文处理,不过每行记得输出2个字符,那样才是一个完整的中文文字: #include <stdio.h>int main(void) { char word[256]int i=0,jwhile(word[i++]=getchar() != '\n') { } for(j=0j<ij+=2) { printf("%c%c",word[j],word[j+1])printf("\n")} return 0} 这个程序只能输入一行不含空格的字符,否则会乱码,需要自己改一下去。

求采纳