Commit 21cf1aea by 20200519053

格式修改

parent e0d0fb5f
No preview for this file type
...@@ -26,28 +26,30 @@ print(''' ...@@ -26,28 +26,30 @@ print('''
3. Levenshetein string distance 3. Levenshetein string distance
''') ''')
stra = input('input first string:') def edit_dist(stra, strb):
strb = input('input second string:') arra = []
arra = [] arrb = []
arrb = [] for c in stra:
for c in stra:
arra.append(c) arra.append(c)
for c in strb: for c in strb:
arrb.append(c) arrb.append(c)
lena = len(arra) lena = len(arra)
lenb = len(arrb) lenb = len(arrb)
lenboud = max(lena,lenb) lenboud = max(lena,lenb)
arrf = [[0 for i in range(0,lenboud+2)]for i in range(0,lenboud+2)] arrf = [[0 for i in range(0,lenboud+2)]for i in range(0,lenboud+2)]
for i in range(1,lenboud+2): for i in range(1,lenboud+2):
arrf[i][0]=i arrf[i][0]=i
arrf[0][i]=i arrf[0][i]=i
for i in range(1,lena+1): for i in range(1,lena+1):
for j in range(1,lenb+1): for j in range(1,lenb+1):
if (arra[i-1]==arrb[j-1]): if (arra[i-1]==arrb[j-1]):
arrf[i][j]=arrf[i-1][j-1] arrf[i][j]=arrf[i-1][j-1]
else: else:
arrf[i][j]=min(arrf[i][j-1],min(arrf[i-1][j],arrf[i-1][j-1]))+1 arrf[i][j]=min(arrf[i][j-1],min(arrf[i-1][j],arrf[i-1][j-1]))+1
print('Levenshetein string distance = ',arrf[lena][lenb]) print('Levenshetein string distance = ',arrf[lena][lenb])
str1 = input('input first string:')
str2 = input('input second string:')
edit_dist(str1,str2)
print(''' print('''
4. Nontechnical problem 4. Nontechnical problem
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment