Commit 21cf1aea by 20200519053

格式修改

parent e0d0fb5f
No preview for this file type
......@@ -26,28 +26,30 @@ print('''
3. Levenshetein string distance
''')
stra = input('input first string:')
strb = input('input second string:')
arra = []
arrb = []
for c in stra:
arra.append(c)
for c in strb:
arrb.append(c)
lena = len(arra)
lenb = len(arrb)
lenboud = max(lena,lenb)
arrf = [[0 for i in range(0,lenboud+2)]for i in range(0,lenboud+2)]
for i in range(1,lenboud+2):
arrf[i][0]=i
arrf[0][i]=i
for i in range(1,lena+1):
for j in range(1,lenb+1):
if (arra[i-1]==arrb[j-1]):
arrf[i][j]=arrf[i-1][j-1]
else:
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])
def edit_dist(stra, strb):
arra = []
arrb = []
for c in stra:
arra.append(c)
for c in strb:
arrb.append(c)
lena = len(arra)
lenb = len(arrb)
lenboud = max(lena,lenb)
arrf = [[0 for i in range(0,lenboud+2)]for i in range(0,lenboud+2)]
for i in range(1,lenboud+2):
arrf[i][0]=i
arrf[0][i]=i
for i in range(1,lena+1):
for j in range(1,lenb+1):
if (arra[i-1]==arrb[j-1]):
arrf[i][j]=arrf[i-1][j-1]
else:
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])
str1 = input('input first string:')
str2 = input('input second string:')
edit_dist(str1,str2)
print('''
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