Coding
[문자열] 1120번
linguana
2021. 4. 29. 16:42
1120번: 문자열
길이가 N으로 같은 문자열 X와 Y가 있을 때, 두 문자열 X와 Y의 차이는 X[i] ≠ Y[i]인 i의 개수이다. 예를 들어, X=”jimin”, Y=”minji”이면, 둘의 차이는 4이다. 두 문자열 A와 B가 주어진다. 이때, A의
www.acmicpc.net
A,B = (input().split())
# slice the B as the size of A for the comparison of match btwn the two strings
best_idx = 0
best_match = 0
for i in range(0, len(B) - len(A) +1):
# slice the B as the size of A
B_comparison = B[i:i+len(A)]
# calculate the match of chars btwn the two strings
match = 0
for idx, char in enumerate(B_comparison):
if char == A[idx]:
match += 1
else:
continue
# check if the match is the maximum, and update best_match
if match > best_match:
best_match = match
best_idx = i
print(len(A) - best_match)