题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
- 思路:既然字符串按照8位拆分,先求出整除的数c和余数o,遍历c次,每次打印8个数,遍历完成之后则还有剩余o个数, 如果o为0,则刚好打印完无需打印,如果o不为0, 剩下只需要拼接(8-o)个"0"即可。
s = input()
n = len(s)
c, o = n // 8, n % 8
for i in range(c):
print(s[(8*i):(8*(i+1))])
else:
if o != 0:
less = s[(8*c):].ljust(8, "0")
print(less)