题解 | #字符串分隔#,为啥我要写这么长才能解出来
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import sys n = 8 # 处理小于8的情况 def processa(stra, str_lenth): if str_lenth==0: return str0 = "" for i in range(n - str_lenth): str0 += "0" print(stra + str0) # 处理大于8的情况 def processb(stra, str_lenth): num = int(str_lenth / n) # print(num) strb = "" for i in range(num + 1): if i < num: print(stra[i * n : (i + 1) * n]) elif i == num: # print(stra[i*8:],len(stra[i*8:])) processa(stra[i * n :], len(stra[i * n :])) else: print("***") stra = input('') str_lenth = len(stra) # print(str_lenth) if str_lenth < n: processa(stra, str_lenth) elif str_lenth == n: print(stra) elif str_lenth > n: processb(stra, str_lenth)