题解 | #字符串分隔#

字符串分隔

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

import sys

def cut(sentence):
    result = []
    length = len(sentence)
    if length <= 8 :
        result.append(sentence + '0'* (8-length))
    elif length > 8 and length <= 100:
        if length % 8 == 0:
            for i in range(int(length / 8)):
                result.append(sentence[i*8: (i+1)*8])
        else:
            times = int(length / 8)
            # print(times)
            yushu = length % 8
            # print(yushu)
            for i in range(times):
                result.append(sentence[i*8: (i+1)*8])
                # print(result)
            result.append(sentence[times*8:] + '0'*(8-yushu))
    # else:
    #     raise Exception('超长')
    return result

if __name__ == '__main__':
    sentence = sys.stdin.readline().strip()
    result = cut(sentence)
    for item in result:
        print(item)

全部评论

相关推荐

喜欢核冬天的哈基米很想上市:会爆NullPointerException的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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