题解 | #参数解析#

参数解析

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容器处理

全部评论

相关推荐

06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:35
程序员小白条:话太多,没实力和学历,差不多回答回答就行了,身份地位不一样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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