题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#大体逻辑都很容易想出来,if else就完事了。但是细化修正逻辑的时候要写测试,非常麻烦
import sys
def strHandle(a):
if len(a)>0 and len(a)<8:
a=a+'0'*(8-len(a))
return a
elif len(a)==0:
return ''
elif len(a)==8:
return a
else:
pass
for line in sys.stdin:
a = line.strip()
if len(a)<=8:
print(strHandle(a))
elif len(a)>8:
b=[]
for i in range(len(a)):
if (i+1)%8==0:
b.append(a[i])
b.append('分隔符')
else:
b.append(a[i])
b=''.join(b)
b=b.split('分隔符')
b[-1]=strHandle(b[-1])
for i in b:
print(i)
elif a=='':
pass
else:
pass