题解 | #参数解析#

参数解析

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

#用的递归的方法, 遇到“”时进行一个内部小循环,返回新的大循环的值
s = input()
n =len(s)
line = []
def canshu(k,n):
    d = ''
    for i in range(k,n):
        if s[i] == ' ':
            if d != '':
                line.append(d)
            d = ''
        elif s[i] == '"':
            for j in range(i+1,n):
                if s[j] == '"':
                    line.append(s[i+1:j])
                    return canshu(j+1,n)
        else:
            d += s[i]
            if i == n-1:
                line.append(d)

canshu(0,n)
print(len(line))
for i in line:
    print(i)

全部评论

相关推荐

2025-12-26 00:57
门头沟学院 golang
菜菜_带带:作弊的前提是你得有真东西,不然很容易就备看出来了,至于混进去,都是面试造火箭,工作拧螺丝罢了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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