主要考虑了有两个以上回文串的情况,取末尾的回文串,然后我就从末尾开始判断,测了一些情况都复合,有错的地方请指正。
#include<stdio.h>
#include<string.h>
int huiwen(char *head,char *rear){
while(head<rear){
if(*head==*rear)
{
head++;
rear--;
}
else
return 0;
}
return 1;
}
char a[1000000];
int main(){
while(scanf("%s",a)){
int len=strlen(a);
int count=0,i=0;
char *rear=a,*head=&a[len-1];
while(head>a){
while(*rear!=*head&&rear<=head)
rear++;
if(head!=rear){
if(huiwen(rear,head)){
count=rear-a;
break;
}
}
head--;
rear=a;
}
if(head==a){
count=len;
}
printf("%d\n",count);
}
return 0;
}

本文介绍了一种用于识别字符串中回文串的算法实现。该算法特别针对包含多个回文子串的情况,通过从字符串末尾开始寻找最长的回文串来解决。文章提供了完整的C语言代码示例。

1260

被折叠的 条评论
为什么被折叠?



