题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
思路1:先对字符串处理,通过余数判断,不足补0,然后循环切片
while True: try: # 输入字符串 s=input() # 空字符串不处理 if s=='': continue else: # 对字符串进行处理,取余数不足补齐 l=len(s) % 8 if l!=0: s+='0'*(8-l) for i in range(0,len(s),8): ss=s[i:i+8] print(ss) except: break思路2:格式化输出 {0:0<8s}".format
while True: try: str_ = input() if len(str_) > 100 or len(str_) == 0: raise Exception else: for i in range(0, len(str_), 8): print("{0:0<8s}".format(str_[i:i + 8])) except Exception as e: break