题解 | #参数解析#
参数解析
http://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
while True: try: s = input().strip() # print(len(s)) # for item in s: # print(item) para = [] temp = '' brackets = 0 #用来判断遇到空格是否结束当前参数 for char in s: if char == '"': brackets ^= 1 #奇数个'"' when brackets equal to zero, it has already counted even number of '"' continue # continue 很重要,不要把引号和空格都加入到参数中 if char == ' ' and brackets == 0: para.append(temp) temp = '' # 记得重置 continue temp += char para.append(temp) # 最后一个temp 因为遇不到空格了,所以还需要手动加入 print(len(para)) for item in para: print(item) except EOFError: break