Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # alignment.py: Reads from standard input, the output produced by
  2. # edit_distance.py, i.e., input strings x and y, and the opt matrix. The
  3. # program then recovers an optimal alignment from opt, and writes to
  4. # standard output the edit distance between x and y and the alignment itself.
  5.  
  6. import stdarray
  7. import stdio
  8.  
  9. # Read x, y, and opt from standard input.
  10. x = stdio.readString()
  11. y = stdio.readString()
  12. opt = stdarray.readInt2D()
  13.  
  14. # Compute M and N.
  15. M = len(x)
  16. N = len(y)
  17.  
  18. # Write edit distance between x and y.
  19. stdio.writef('Edit distance = %1d\n', opt[0][0])
  20.  
  21. # Recover and write an optimal alignment.
  22. for i in range(0, M + 1):
  23. for j in range(0, N + 1):
  24. while i < M and j < N:
  25. if opt[i][j] == opt[i + 1][j] + 2:
  26. stdio.writeln(str(x[i]) + ' - 2')
  27. stdio.writeln('first if statement')
  28. i += 1
  29. elif opt[i][j] == opt[i][j + 1] + 2:
  30. stdio.writeln(str(y[j]) + ' - 2')
  31. stdio.writeln('first elif statement')
  32. j += 1
  33. else:
  34. if x[i] == y[j]:
  35. stdio.writeln(str(x[i]) + ' ' + str(y[j]) + ' 0')
  36. stdio.writeln('first else statement')
  37. i += 1
  38. j += 1
  39. else:
  40. stdio.writeln(str(x[i]) + ' ' + str(y[j]) + ' 1')
  41. i += 1
  42. j += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement