2016-12-17 1 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' '으로 표시됩니다. fucntion을 인수로 사용할 수 있습니다. – MYGz

답변

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 

당신은 유용한 엄지 손가락을 찾을 경우 up