-문제: 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)
'백준 > Greedy' 카테고리의 다른 글
[그리디/백준] 1783번: 병든 나이트 (0) | 2022.07.07 |
---|---|
[그리디/백준] 2847번: 게임을 만든 동준이 (0) | 2022.07.07 |
[그리디/백준] 2437번: 저울 (0) | 2022.07.05 |
[그리디/백준] 1449번: 수리공 항승 (0) | 2022.07.05 |
[그리디/백준] 1080번: 행렬 (0) | 2022.07.04 |