110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlInt32 simil(string str1, string str2)
{
int len1 = str1.Length;
int len2 = str2.Length;
int lenLCS;
// unsigned *previous, *next;
if (len1 == 0 || len2 == 0)
return 0;
int[] previous = new int[len1 + 1];
int[] next = new int[len1 + 1];
int[] temp = new int[len1 + 1];
//next=(unsigned *)calloc( len1+1, sizeof(unsigned));
for (int j = 0; j < len2; ++j)
{
for (int k = 1; k <= len1; ++k)
if (str1[k - 1] == str2[j])
next[k] = previous[k - 1] + 1;
else next[k] = previous[k] >= next[k - 1] ? previous[k] : next[k - 1];
temp = next;
next = previous;
previous = temp;
//swap( &previous, &next);
}
lenLCS = previous[len1];
return new SqlInt32(lenLCS);
}
};