python解法

参数解析

http://www.nowcoder.com/questionTerminal/668603dc307e4ef4bb07bcd0615ea677

python解法

coding: utf-8

if name =='main':

str = raw_input()
flag = 0
sum =0
i =0
list = []
start = end = 0

# print 'len:',len(str)
while i < len(str):
    if str[i] == ' ':
        sum +=1
        end = i
        list.append(str[start:end])
        start = end+1

    if str[i] == '"':
        # print 'flag=1',i
        start = i+1
        flag = 1
    while flag == 1:
        i +=1
        if str[i] == '"':
            # print 'flag == 0',i
            end = i
            flag = 0
        list.append(str[start:end])
    i= i+1
if end == len(str)-1:  #表示加过了
    pass
else:
    end = len(str)
    list.append(str[start:end])

    # print 'i:',i
print sum+1
for i in list:
    print i
全部评论

相关推荐

小马云表哥:我秋招一般是说要出国留学了
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务