题解 | #参数解析#

参数解析

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

from operator import le
while 1:
    try:
        command = input()

        parament = []

        mark = 0

        parament0 = ''

        for i in range(len(command)):
            if command[i] == '"' and mark == 0:
                mark = 1
                continue
            elif command[i] == '"' and mark == 1:
                mark = 0
                continue
            
            if mark == 1:
                parament0 += command[i]
                if command[i + 1] == '"':
                    parament.append(parament0)
                    parament0 = ''
                    continue
            elif mark == 0 and command[i] == ' ':
                continue
            elif mark == 0:
                parament0 += command[i]
                if i + 1 == len(command) or command[i + 1] == ' ':
                    parament.append(parament0)
                    parament0 = ''

        print(len(parament))
        for i in range(len(parament)):
            print(parament[i], end='\n')

    except:
        break

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务