题解 | #字符串分隔#

字符串分隔

http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

in_str = input()

使用字符串的lstrip还是rstrip方法补零,方法忘了,查一下

采用长度对8取余法,余数是多少,就补充8-余数个零

zero_count = 8-(len(in_str)%8) #print(zero_count) if zero_count ==8: zero_count=0 # 余数是0,zero—count 是8,不能补充 new_str = in_str+'0'*zero_count # 字符串拼接

输出看一下,结果8个0,% 和//又用错了

print(new_str)

对字符串进行截取输出,不会用函数,只能循环了

for i in range(1,len(new_str)+1): #print(i) print(new_str[i-1],end='') if i%8==0: print()

全部评论
写错了,应该是rjust()和ljust()
点赞 回复 分享
发布于 2022-04-16 12:21

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务