34.回文子串

题目没有本身没有多大的难度,只要找清楚所要找的东西就够了(如上面出发点的头,出发点的尾等),建议画图打好草稿理清思路后在开始做题。
 1  #include <stdio.h>
 2 #include <string.h>
 3 int main(int argc, char *argv[])
 4 {
 5 char str[100];
 6 int n,x,y;
 7 scanf("%s",str);
 8 n=strlen(str);
 9 for(int i=2;i<=n;i++)//i长度 
10 {
11 for(int j=0;j<=n-i;j++)//j出发点 
12 {
13 for(x=j,y=j+i-1;x<y;x++,y--)//x出发点的头 j+i-1出发点的尾 
14 {
15 if(str[x]!=str[y]) break;//如果头不等于尾就咔掉 
16 }
17 if(!(x<y)) 
18 {
19 for(x=j,y=j+i-1;x<=y;x++) printf("%c",str[x]);
20 printf("\n");              
21 }
22 }
23 }
24 return 0;
25 } 

猜你喜欢

转载自www.cnblogs.com/sona/p/10301836.html