C#计算字符串相识度

时间:2019-08-15 07:04:28
【文件属性】:

文件名称:C#计算字符串相识度

文件大小:7KB

文件格式:CS

更新时间:2019-08-15 07:04:28

字符串相识度

this.InitMatrix(); int intCost = 0; for (int i = 1; i < _Row; i++) { for (int j = 1; j < _Column; j++) { if (_ArrChar1[i - 1] == _ArrChar2[j - 1]) { intCost = 0; } else { intCost = 1; } //关键步骤,计算当前位置值为左边+1、上面+1、左上角+intCost中的最小值 //循环遍历到最后_Matrix[_Row - 1, _Column - 1]即为两个字符串的距离 _Matrix[i, j] = this.Minimum(_Matrix[i - 1, j] + 1, _Matrix[i, j - 1] + 1, _Matrix[i - 1, j - 1] + intCost); _ComputeTimes++; } } //结束时间 //_EndTime = DateTime.Now; //相似率 移动次数小于最长的字符串长度的20%算同一题 int intLength = _Row > _Column ? _Row : _Column; _Result.Rate = (1 - (decimal)_Matrix[_Row - 1, _Column - 1] / intLength); // _Result.UseTime = (_EndTime - _BeginTime).ToString(); _Result.ComputeTimes = _ComputeTimes.ToString(); _Result.Difference = _Matri


网友评论