回文字符串

来源:互联网 发布:软件编制资质 编辑:程序博客网 时间:2024/05/22 02:13
找最长回文字符串
#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;}

0 0
原创粉丝点击