Longest-common-subsequence-.../main.py
2024-12-08 23:11:33 +08:00

21 lines
640 B
Python

from LCS import longest_common_subsequence
from MED import min_edit_distance
def main():
print("测试:最长公共子序列和最小编辑距离")
# 输入字符串
str1 = "ABCBDAB"
str2 = "BDCAB"
# 测试最长公共子序列
lcs_length = longest_common_subsequence(str1, str2)
print(f"字符串 '{str1}''{str2}' 的最长公共子序列长度为:{lcs_length}")
# 测试最小编辑距离
edit_distance = min_edit_distance(str1, str2)
print(f"将字符串 '{str1}' 转换为 '{str2}' 的最小编辑距离为:{edit_distance}")
# 运行主函数
if __name__ == "__main__":
main()