题解 | #参数解析# #简单易懂#

参数解析

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

string = input()
#基本思路是先用"分割,但是我想保留"",所以我把”换成```"
string = string.replace(' "','```"')
string = string.replace('" ','"```')
#用```分割,这样可以保留"
string = string.split('```')

result = []
for i in string:
    #如果是正常的中间没有空格而且不是引号
    if ' ' not in i and i[0]!='"':
        result.append(i)
    #如果有引号,那就去掉引号加入我们的result
    elif i[0]=='"':
        i=i.replace('"','')
        result.append(i)
    #如果没有引号而且中间有空格,代表需要进一步分割,按空格分割
    else:
        result.append(i.split())
count = 0
#先数一下这个二维list有多少个东西
for i in result:
    if type(i)!=list:
        count+=1
    else:
        for j in i:
            count+=1
#打印出来有几个东西
print(count)
#打印出来结果
for i in result:
    if type(i)!=list:
        print(i)
    else:
        for j in i:
            print(j)


全部评论

相关推荐

二十岁的编程男神王大...:读博吧兄弟,你这绩点太好了,何必转码,另外哈哈哈真见到有括号标出来985的,这个不标注也知道吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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