新版本公告
~~空空如也
加载中
加载中
表情图片
评为精选
鼓励
加载中...
分享
加载中...
文件下载
加载中...
Delphi的实现方法,写了百分比的函数 。。。【注意form1,直接复制要改代码】


function Form1.Levenshtein_Distance(str1: string; str2: string): Double;
begin
    d := 0;
    if (str1.Length > str2.Length) then
        d := str1.Length
    else
        d := str2.Length;
    begin
        Result := (1 - ((self.LD(str1, str2) as Double) div (d as Double)));
        exit
    end
end;


function Form1.LD(s: string; t: string): Integer;
var
    i: Integer;
    cost: Integer;
begin
    n := Strings.Len(s);
    m := Strings.Len(t);
    if (n = 0) then
        begin
            Result := m;
            exit
        end;
    if (m = 0) then
        begin
            Result := n;
            exit
        end;
    dis := New(array[(n + 1), (m + 1)] of Integer);
    VBti4L0 := n;
    i := 0;
    while ((i <= VBti4L0)) do
    begin
        dis[i, 0] := i;
        inc(i)
    end;
    VBti4L1 := m;
    j := 0;
    while ((j <= VBti4L1)) do
    begin
        dis[0, j] := j;
        inc(j)
    end;
    VBti4L2 := n;
    i := 1;
    while ((i <= VBti4L2)) do
    begin
        s_i := Strings.Mid(s, i, 1);
        VBti4L3 := m;
        j := 1;
        while ((j <= VBti4L3)) do
        begin
            t_j := Strings.Mid(t, j, 1);
            if (s_i = t_j) then
                cost := 0
            else
                cost := 1;
            dis[i, j] := self.Minimum((dis[(i - 1), j] + 1), (dis[i, (j - 1)] + 1), (dis[(i - 1), (j - 1)] + cost));
            inc(j)
        end;
        inc(i)
    end;
    LD := dis[n, m];
    dis := nil;
    begin
        Result := LD;
        exit
    end
end;

function Form1.Minimum(a: Integer; b: Integer; c: Integer): Integer;
begin
    min := a;
    if (b < min) then
        min := b;
    if (c < min) then
        min := c;
    begin
        Result := min;
        exit
    end
end;
文号 / 141033

万流景仰
名片发私信
学术分 30
总主题 651 帖总回复 6037 楼拥有证书:学者 笔友
注册于 2007-04-10 19:15最后登录 2018-01-10 01:07
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:未同步

个人简介

暂未填写
文件下载
加载中...
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

插入资源
全部
图片
视频
音频
附件
全部
未使用
已使用
正在上传
空空如也~
上传中..{{f.progress}}%
处理中..
上传失败,点击重试
等待中...
{{f.name}}
空空如也~
(视频){{r.oname}}
{{selectedResourcesId.indexOf(r.rid) + 1}}
处理中..
处理失败
插入表情
我的表情
共享表情
Emoji
上传
注意事项
最大尺寸100px,超过会被压缩。为保证效果,建议上传前自行处理。
建议上传自己DIY的表情,严禁上传侵权内容。
点击重试等待上传{{s.progress}}%处理中...已上传,正在处理中
空空如也~
处理中...
处理失败
加载中...
草稿箱
加载中...
此处只插入正文,如果要使用草稿中的其余内容,请点击继续创作。
{{fromNow(d.toc)}}
{{getDraftInfo(d)}}
标题:{{d.t}}
内容:{{d.c}}
继续创作
删除插入插入
插入公式
评论控制
加载中...
文号:{{pid}}
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的