题解 | #参数解析#

参数解析

https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677

# key is to deal with ""
# when flag is off, split on space; when it's on, includes space


s = input() + ' '   # for the last element to be added to the list

f = False
p = ''
l = []

for i in s:
    if i == '"':
        f = not f

    elif not f and i == ' ':
        l.append(p)
        p = ''

    else:
        p += i

print(len(l))
for j in l:
    print(j)

参考题解 | #参数解析-巧妙将一长串分行打印#_钻石王老五的flag开关用法,用list容器处理

全部评论

相关推荐

点赞 评论 收藏
分享
无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务