题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import sys #输入字符串 demo = input() #计算字符串长度 demo_len = len(demo) if demo_len <= 0: #字符串为空不处理 pass elif demo_len>0 and demo_len < 8 : #字符串长度小于8 print( demo + "0"*(8-demo_len) ) elif demo_len >= 8 and demo_len % 8 == 0: #字符串长度为8的倍数 res = [] for item in range(demo_len): res.append(demo[item]) if len(res) == 8: print(''.join(res)) res = [] elif demo_len > 8 and demo_len % 8 != 0: #长度大于8且不能整除8 res = [] front_len = demo_len - demo_len % 8 for item in range(demo_len): if item < front_len: #打印整除部分 res.append(demo[item]) if len(res) == 8: print(''.join(res)) res = [] else: res.append(demo[item]) print(''.join(res) + "0" * (8- demo_len%8)) #打印余数部分