找最长回文字符串
#include <stdio.h>
int main()
{
char str[100];
int i;//循环变量
int n;//字符串位数
int temp1,temp2;
int j = 1;
int count = 0;
int flag = 0;
printf("输入字符串(100个字符以内):");
scanf("%s",str);
printf("输入字符串位数:");
scanf("%d",&n);
for(i = 0;i < n;i++)
{
// while( i != (n - j))
{
for(j = 1;j < n;j++)
{
temp1 = i;
temp2 = j;
while(str[temp1] == str[n - temp2])
// while(strcmp(str[temp1],str[n - temp2]) == 0)
{
if((temp1 == (n - temp2))/* || ((temp1 + 1) == (n - temp2))*/)
{
// flag = count;
flag = n - j - i + 1;
// count = temp2 -temp1;
if(count < flag)
{
count = flag;
}
break;
}
else
{
temp1++;
temp2++;
}
}
}
}
}
printf("\n返回:%d\n",count);
return 0;
}