2016-12-17 10 views
-1

単語を単語に分割し、スペースと改行に基づいて行を分割するタスクが与えられました。私は最後の言葉を印刷しないので、不完全な解決策を思いついた。私は線形探索だけで基本的なアプローチを使用することができます。ありがとう。単語を単語に分割するタスク - リニア検索の方法

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

'string.split()'を使うこれをチェックする:http://stackoverflow.com/questions/40955656/what-does-python-splitr-means/40955737#40955737 – MYGz

+0

スペースは ''''で表され、改行は「\ n」で示されます。機能を分割するための引数として使用できます。 – MYGz

答えて

0

私はあなたがそれ役に立つ親指を見つけた場合、あなたのコンセプト


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 

を明確にするために、この例を参照してくださいあなたの問題は、これがHackerearth問題


に幾分類似であることを理解します上へ