题解 | #字符串分隔#

字符串分隔

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

def get_ans(s):
    if not s: return None
    if len(s)==8: return s
    elif 0<len(s)<8: return add_zero(s)
    else:
        li=[]
        tup=divmod(len(s),8)
        for i in range(tup[0]):
            li.append(s[8*i:8*(i+1)])
        if tup[-1]!=0:
            li.append(get_ans(s[-tup[1]:]))
        return '\n'.join(li)

def add_zero(s):
    li=[]
    for i in s: li.append(i)
    length=len(li)
    for i in range(length,8):
        li.append('0')
    return ''.join(li)

if __name__=='__main__':
    import sys
    lines = []
    while True:
        line = sys.stdin.readline().strip()
        if line == "":
            break
        lines.append(line)
    # 单个取
    for item in lines:
        print(get_ans(item))
题解-数据结构与算法 文章被收录于专栏

小菜鸟的题解

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 10:39
一个证都没&nbsp;我能填什么
程序员小白条:别人有,你为什么没有,还是这个道理,社会就是比较,竞争,淘汰,你要安逸,那么就要做好淘汰的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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