解题思路:1.创建存储最终结果的字符串list_s,创建栈存储当前字符串;
2.分情况判断,1)临时栈中已存在"再次遇到";2)临时栈中不存在”遇到空格且不为空栈;3)其他情况
s = input()
list_s = []#存储全部字符串
list_l = []#存储前字符串
n = 0
for i in s:
if i =='"' and '"' in list_l:#如果“已经存在于临时表中 且在此遇到”
list_s.append(''.join(list_l[1::]))
list_l = []
n+=1
elif i == ' ' and '"' not in list_l:#如果“不存在于临时表中 遇到空格
if len(list_l) != 0:
list_s.append(''.join(list_l[0::]))
list_l = []
n+=1
else:
list_l.append(i)
if len(list_l) != 0:
list_s.append(''.join(list_l[0::]))
n+=1
print(n)
print('\n'.join(list_s))

京公网安备 11010502036488号