题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
def split_string(s):
# 如果字符串长度不是8的倍数,那么在其末尾添加0,使其长度达到8的倍数
if len(s) % 8 != 0:
s += '0' * (8 - len(s) % 8)
# 使用列表推导式来拆分字符串,每8个字符为一个片段
processed_list = [s[i:i+8] for i in range(0, len(s), 8)]
result1 = '\n'.join(processed_list)
return result1
else:
processed_list2 = [s[i:i+8] for i in range(0, len(s), 8)]
result2 = '\n'.join(processed_list2)
return result2
# return s
# 接收用户输入
input_strings = input().split()
# 对每个输入的字符串进行处理并输出结果
for s in input_strings:
print(split_string(s))
#我的实习求职记录#
查看18道真题和解析