题目大意
给一个字符串,要求以U
型输出这个字符串,例如helloworld
,输出:
h**d
e**l
l**r
lowo
为了展示方便我将空格替换成了*
U
型输出时的左边一列的长度left
等于右边一列的长度right
,设底部的长度bottom
,字符串的总长度为n
。则有left+right+bottom-2=n
,且left
和right
尽可能的大
输入
每组包含一个测试用例,每个用例是一行字符串且长度不少于5不大于80
输出
对每个用例以U
型输出字符串
样例输入
helloworld!
样例输出
h ~~~ !
e ~~~ d
l ~~~ l
lowor
解析
由题意left=right=(n + 2) / 3
, bottom=left + (n + 2) % 3
,然后按照要求输出即可
# -*- coding: utf-8 -*-
# @Time : 2019/5/28 18:17
# @Author : ValarMorghulis
# @File : 1031.py
def solve():
s = input()
left = (len(s) + 2) // 3
bottom = left + (len(s) + 2) % 3
for i in range(left):
if i != left-1:
print(s[i], end='')
for j in range(bottom-2):
print(' ', end='')
print(s[len(s)-1-i])
else:
print(s[left-1:left+bottom-1])
if __name__ == "__main__":
solve()