本文目录一览

1,最长公共回文子序列的长度

最长公共回文子序列的长度。return f(x1,y1); 这递归只能 求 同位置的 最长公共子序列的长度啊 ex: a123456hhh c1234588888 得到5 ex: ab123456hhh c1234588888 这样的只能得到0了。。

最长公共回文子序列的长度

2,输入一个字符串求出其中最长的回文子串 注意判断时忽略所有标

#includeusing namespace std; char s[100]; int recurs(int i,int j) { if(s[i]!=s[j])return 0; else if(i>j-2)return 1; else return return(i+1,j-1); } void main() { int i; cout<<"输入一个字符串:"; cin>>s; for(i=0;s[i];i++); if(recurs(0,i-1)) cout<<"是回文串"< else cout<<"不是回文串"< }
没人写还是给你写一个吧,算法一般般的。、#includevoid exchange(int *a,int *b) { int c; c=*a; *a=*b; *b=c; } bool ishuiwen(char c[],int start,int end) { int i; for(i=0;i<=(end-start)/2;i++) if(c[start+i]!=c[end-i]) return 0; return 1; } void main() { char c[100]; int i,j; int start[100],end[100],len[100]; int e=0; gets(c); for(i=0;i for(j=strlen(c)-1;j>i;j--) { if(ishuiwen(c,i,j)) {start[e++]=i,end[e]=j,len[e]=j-i+1;} } for(i=0;i for(j=0;j if(len[j]>len[j+1]) { exchange(&start[j],&start[j+1]); exchange(&end[j],&end[j+1]); exchange(&end[j],&end[j+1]); } for(i=0;len[i]!=0;i++) { for(j=start[i];j<=end[j];j++) putchar(c[j]); printf("\n"); } } 算法感觉不是太好,将就一下

输入一个字符串求出其中最长的回文子串 注意判断时忽略所有标

3,输入一个字符串求出其中最长的回文子段

#includeusing namespace std; char s[100]; int recurs(int i,int j) { if(s[i]!=s[j])return 0; else if(i>j-2)return 1; else return return(i+1,j-1); } void main() { int i; cout<<"输入一个字符串:"; cin>>s; for(i=0;s[i];i++); if(recurs(0,i-1)) cout<<"是回文串"< else cout<<"不是回文串"< }
没人写还是给你写一个吧,算法一般般的。、#includevoid exchange(int *a,int *b) { int c; c=*a; *a=*b; *b=c; } bool ishuiwen(char c[],int start,int end) { int i; for(i=0;i<=(end-start)/2;i++) if(c[start+i]!=c[end-i]) return 0; return 1; } void main() { char c[100]; int i,j; int start[100],end[100],len[100]; int e=0; gets(c); for(i=0;i for(j=strlen(c)-1;j>i;j--) { if(ishuiwen(c,i,j)) {start[e++]=i,end[e]=j,len[e]=j-i+1;} } for(i=0;i for(j=0;j if(len[j]>len[j+1]) { exchange(&start[j],&start[j+1]); exchange(&end[j],&end[j+1]); exchange(&end[j],&end[j+1]); } for(i=0;len[i]!=0;i++) { for(j=start[i];j<=end[j];j++) putchar(c[j]); printf("\n"); } } 算法感觉不是太好,将就一下

输入一个字符串求出其中最长的回文子段


文章TAG:最长回文子串  最长公共回文子序列的长度  
下一篇