我已经完成了将线条分割成单词然后根据空格和换行分割线条的任务。我想出了一个不完整的解决方案,因为它不会打印最后一个字。我只能使用线性搜索,因此是基本方法。感谢。
line = raw_input()
while line != "end":
i = 0
while i < len(line):
i = 0
while i < len(line) and line[i] == " ":
i = i + 1
j = i
while line[j] != " ":
j = j + 1
print line[i:j]
line = line[j:]
line = raw_input()
答案 0 :(得分:0)
我理解你的问题,这有点类似于Hackerearth问题
请参阅此示例以阐明您的概念
y=list()
1). y=map(int,raw_input().split()) # for storing integer in list
2). y=map(str,raw_input().split()) # for storing characters of string in list
#then use this to print the value
for i in y:
print i #this loop will print one by one value
#working example of this code is #for Second part
>>baby is cute #input
>>['baby','is','cute'] #output
>> #now according to your problem line is breaks into words
如果您发现拇指向上有用