상세 컨텐츠

본문 제목

[문자열] 1120번

Coding

by linguana 2021. 4. 29. 16:42

본문

1120번: 문자열 (acmicpc.net)

 

1120번: 문자열

길이가 N으로 같은 문자열 X와 Y가 있을 때, 두 문자열 X와 Y의 차이는 X[i] ≠ Y[i]인 i의 개수이다. 예를 들어, X=”jimin”, Y=”minji”이면, 둘의 차이는 4이다. 두 문자열 A와 B가 주어진다. 이때, A의

www.acmicpc.net

bakjoon1120.ipynb
0.00MB

 

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)

'Coding' 카테고리의 다른 글

Autokeras 오토케라스  (0) 2021.05.04
주식가격  (0) 2021.04.30
알고리즘 공부 추천 순서  (0) 2021.04.29
2019 카카오 개발자 겨울 인턴십 코테  (0) 2021.04.28
Attention (youtube link)  (0) 2021.04.13

관련글 더보기