Skip to content

Instantly share code, notes, and snippets.

@uchidama
Created July 7, 2021 15:46
Show Gist options
  • Save uchidama/00577ea39afed26a2d7f28dd1057f201 to your computer and use it in GitHub Desktop.
Save uchidama/00577ea39afed26a2d7f28dd1057f201 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 177 [ B - Substring ] https://atcoder.jp/contests/abc177/tasks/abc177_b
'''
[問題]
https://atcoder.jp/contests/abc177/tasks/abc177_b
[解説]
https://atcoder.jp/contests/abc177/editorial/87
'''
import sys
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
S = input()
S = S.replace( '\n' , '' )
T = input()
T = T.replace( '\n' , '' )
ans = len(T)
# SとTを総当たりで見ていって、何文字違うかカウントする。その最小値が答え
for S_START in range(0, len(S) - len(T) + 1):
diff = 0
for i in range(0, len(T)):
if S[S_START + i] != T[i]:
diff += 1
ans = min(ans, diff)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment