본문 바로가기

개발자 강화/코딩 테스트

[백준] 1543 문자 검사 / 구현 / Python

https://www.acmicpc.net/problem/1543

 

string.find로 key(찾는 문자열)의 index를 구한 후, index 지점부터 key 길이만큼 1로 치환하고, 단어 count을 1 증가시킨다

string.find로 key가 검색되지 않을 때까지 while문으로 반복한다

 

count를 반환한다

 

n = str(input())
key = str(input())
count=0
while True:
    if n.find(key)==-1:
        break
    else:
        count+=1
        idx = n.find(key)

        s = list(n)
        for i in range(idx,idx+len(key)):
            s[i]="1"
        n = ''.join(s)

print(count)