""" dp[i][j] i-1 为 str2 第 i 个字符 j-1 为 str1 第 j 个字符 例如: str1 = abc str2 = abcde 假设始终对str1进行操作 输出为dp[5][3] 添加: str1 = abc+e str2 = abcde 即dp[5][3] = dp[4][3] + 1 即dp[i][j] = dp[i-1][j] + 1 删除: str1 = abc-c str2 = abcde 即dp[5][3] = dp[5][4] + 1 即dp[i][j] = dp[i][j-1] + 1 替换: str1 = abc → abe str2 = abcde 同时去掉e,转换为 str1 = ab str2 = abcd 即dp[5][3] = dp[4][2] + 1 即dp[i][j] = dp[i-1][j-1] + 1 """ while True: try: str1 = input() str2 = input() m = len(str1) n = len(str2) dp = [[1] * (m + 1) for i in range(n + 1)] for i in range(m + 1): dp[0][i] = i for j in range(n + 1): dp[j][0] = j for i in range(1, n + 1): # i-1为str2第i个字符 for j in range(1, m + 1): # j-1为str1第j个字符 if str1[j - 1] == str2[i - 1]: dp[i][j] = dp[i - 1][j - 1] else: a_d_d = dp[i - 1][j] + 1 d_e_l = dp[i][j - 1] + 1 re_pl_ace = dp[i - 1][j - 1] + 1 dp[i][j] = min(a_d_d, d_e_l, re_pl_ace) print(dp[n][m]) except: break