三九宝宝网宝宝百科宝宝知识

最长连续字符串

03月04日 编辑 39baobao.com

[求N个字符串的最长公共子串]求N个字符串的最长公共子串,N<=20,字符串长度不超过255。例如:N=3,由键盘依次输入三个字符串为What is local bus ?Name some local buses.local bus is a high speed I/O bus close...+阅读

#include

#include

#define MAXLENGTH 100struct MaxLengthString

{

private:

char string[MAXLENGTH];

int count;

public:

void ReadString()

{

count = 1;

gets(string);

}

int getLength()

{

int templen = 1; for(char *c=&string[1];*c!='\0';++c)

{

char a = *c;

char b = *(c-1); if(a==b)

{

templen++;

}

else

{

count = templen;

templen = 1;

}

} if(templen>count)

{

count = templen;

}

return count;

}

};int main()

{

int num = 0;

scanf("%d\n",&num);

MaxLengthString *ms = new MaxLengthString[num];

for(int i=0;i{

(ms+i)->ReadString();

}

for (int j=0;j{

printf("%d\n",(ms+j)->getLength());

}

delete ms;

system("pause");}

如何求两个字符串的最长子串

//求使用最长子串使用LCS算法char* LCS(char left[],char right[]) { //获取左子串的长度,获取右子串的长度 int lenLeft=strlen(left),lenRight=strlen(right),k; //注意这里要写成char型,而不是int型,否则输入整型数据时会产生错误。 //矩阵c纪录两串的匹配情况 char*c=malloc(lenRight),*p; //int c[M][M]={0};//当将c申明为一个二维数组时 int start,end,len,i,j;//start表明最长公共子串的起始点,end表明最长公共子串的终止点 end=len=0;//len表示最长公共子串的长度 for(i=0; i=0; j--) { if(left[i] == right[j])//元素相等时 { if(i==0||j==0) c[j]=1;//c[i][j]=1; else { c[j]=c[j-1]+1;//c[i][j]=c[i-1][j-1]+1; } } else c[j] = 0; //c[i][j]=0; if(c[j] >len) //if (c[i][j]>len) { len=c[j]; //len=c[i][j]; end=j; } } } start=end-len+1; //数组p纪录最长公共子串 p =(char*)malloc(len+1); for(i=start; i

C字符串中的最长的字母子串

// 思路: 把字符串拆成单词的数组,再比较它们的长度,最后得到最长的。 #include#include#include#include#includeusing namespace std;const string TEXT("Apple$12pear watermelon $ # Banana"); // 原字符串 // 定义比较字符串长度的仿函数 class CompareStringLength{public: bool operator ()(const string &s1, const string &s2) { return s1.size()

以下为关联文档:

WinAPI字符字符串函数1:CharLower字符字符串转小写unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TBu...

WinAPI字符字符串函数3:CharUpper字符字符串转大写interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Button...

WinAPI字符字符串函数10:lstrcpy复制字符串interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Button...

WinAPI字符字符串函数9:lstrcat合并字符串interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button...

java怎么替换字符串某个字符replace方法 该方法的作用是替换字符串中所有指定的字符,然后生成一个新的字符串。经过该方法调用以后,原来的字符串不发生改变。例如: String s = “abcat”; String s1 = s.r...

java怎么替换字符串中的字符public static void main(String[] args) { String str="some str"; str=str.replace('s','a'); // 按字符来进行替换,所有字符会被替换 str=str.replace("a","s"); // 按字符串来进...

字符串比较函数strcp比较的是字符串的什么你是问strcmp函数么? strcmp函数是比较两个字符串的大小,返回比较的结果。一般形式是: strcmp(字符串1,字符串2); ①字符串1小于字符串2,strcmp函数返回一个负值; ②字符串1等于字...

SQL判断字符串是否在目标字符串中的函数根据需求,写了一段方法。 用于识别以下的情况: 判断 字符串A 在用逗号分隔的字符串B中是否存在如: v_str_a = aa ; v_str_b= aa,bb,dd,cc ; 如上,就返回Y,否则返回N. 添加了一些校...

求两个输入的字符串的最长公共子串求两个输入的字符串的最长公共子串,如何获取多个字符串中最长的共同子字符串:1. 算法:求两个字符串的最长公共子串 2. 原理: (1) 将连个字符串分别以行列组成一个矩阵。 (2)。若...

推荐阅读
图文推荐