题解 | #参数解析#
参数解析
http://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
设一个参数yin,当yin=0时,说明现在指针i在引号外。当yin=1时,在引号内。
import sys
for line in sys.stdin:
line = line[:-1]
yin,i,start = 0,0,0
list1 = []
while i < len(line):
if line[i] == '"' and yin == 0:
yin = 1
start = i+1
elif line[i] == '"' and yin == 1:
list1.append(line[start:i])
start = i + 2 #引号后面是空格
yin = 0
i = i + 1#要跳开引号后面紧跟的空格
elif line[i] == ' ' and yin == 0:
list1.append(line[start:i])
start = i+1
elif i == len(line)-1 and line[-1] != '"':
list1.append(line[start:])
i = i+1
print(len(list1))
for j in list1:
print(j)