[백준 1120][Python] 문자열

봉글렛·2023년 1월 31일

백준

목록 보기
46/55

문제 링크 https://www.acmicpc.net/problem/1120

for문과 while문 중에 고민했지만 확실히 for문을 사용할 수 있다면 더 안정감이 있다.

풀이

while 문

a, b = input().split()
n = 0
result = 50
while len(a)+n <= len(b):
    s = 0
    for i in range(len(a)):
        if a[i] != b[i+n]:
            s += 1
    n += 1
    if result > s:
        result = s
print(result)

for 문

a, b = input().split()

result = 50
for n in range(len(b)-len(a)+1):
    s = 0
    for i in range(len(a)):
        if a[i] != b[i+n]:
            s += 1
    if result > s:
        result = s
print(result)
profile
어쩌다 개발자 (할 수 있을 때까지!!!!)

0개의 댓글