-문제: https://www.acmicpc.net/problem/1543

 

-정답풀이:

아이디어는 맞았는데, 세세한 부분이 부족해서 헤맸다 

종료 조건과, else문 설정을 정확히 하지 않아서 시간초과가 났다

그래도 인덱스 슬라이싱으로 문자 비교하려고한 건 맞았다

 

first=list(input())
second=list(input())
n=len(second)
m=len(first)
count=0
start=0
end=n

while True:
    if start > m-n :
        break
    if first[start:end] == second:
        count+=1
        start=start+n
        end=end+n
    else: 
        start+=1
        end+=1
                            
print(count)

 

-이전 풀이

first=list(input())
second=list(input())
n=len(second)
m=len(first)
count=0
start=0
end=n-1

while True:
    if start > m-n-1 :
        break
    if first[start:end] == second:
        count+=1
        start=end+1
        end=end+n-1
                            
print(count)

+ Recent posts