zoukankan      html  css  js  c++  java
  • 编辑距离问题 模板

    输入

    第1行:字符串a(a的长度 <= 1000)。
    第2行:字符串b(b的长度 <= 1000)。
    输出
     
    输出a和b的编辑距离
     
    输入示例

    kitten
    sitting

    输出示例

    3
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<string>
    using namespace std;
    
    int f[1001][1001];
    char a[1001],b[1001];
    int main()
    {
    cin>>a;
    cin>>b;
    for(int i=1;i<=strlen(a) ;++i) f[i][0]=i;
    for(int j=1;j<=strlen(b) ;++j) f[0][j]=j;
    for(int i=1;i<=strlen(a);++i)
    {
    for(int j=1;j<=strlen(b);++j)
    {
    if(a[i-1]==b[j-1]) f[i][j]=f[i-1][j-1];
    else f[i][j]=min(min(f[i-1][j-1],f[i-1][j]),f[i][j-1])+1;
    }
    }
    cout<<f[strlen(a)][strlen(b)];
    }
    View Code
    我们都在命运之湖上荡舟划桨,波浪起伏着而我们无法逃脱孤航。但是假使我们迷失了方向,波浪将指引我们穿越另一天的曙光。
  • 相关阅读:
    Java——GUI
    linux变量
    shell脚本
    linux查找文件命令
    composer的安装
    restful的nginx配置方法
    api调用安全
    PHP设置Cookie的HTTPONLY属性
    php的异常处理
    php错误报告
  • 原文地址:https://www.cnblogs.com/ruojisun/p/6071487.html
Copyright © 2011-2022 走看看