Created
May 4, 2017 10:13
-
-
Save orsinium/8e69fb4684054bf1ec7ac9986f9da7fc to your computer and use it in GitHub Desktop.
Расстояние Дамерау между двумя текстами.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f(s1, s2): | |
if not s1 or not s2: | |
return len(s1)+len(s2) | |
elif s1[-1]==s2[-1]: | |
return f(s1[:-1], s2[:-1]) | |
else: | |
#вставка/удаление | |
a = min(f(s1[:-1], s2), f(s1, s2[:-1])) | |
#замена | |
b = f(s1[:-1], s2[:-1]) | |
return min(a, b)+1 | |
if __name__ == '__main__': | |
while 1: | |
print(f(input('1: '), input('2: '))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment