字符串中对称子串的个数

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1744

 1 #include<stdio.h>
 2 #include<string.h>
 3 char str[5005];
 4 int main()
 5 {
 6     int len,cnt;
 7     while(scanf("%s",str)!=EOF)
 8     {
 9         len=strlen(str);
10         cnt=len;
11         for(int i=0;i<len;i++)
12         {
13             for(int j=1;j<=i&&j<=len-1;j++)
14             {
15                 if(str[i-j]==str[i+j])
16                     cnt++;
17                 else
18                     break;
19             }
20             for(int j=1;j<=len-1-i&&j-1<=i;j++)
21             {
22                 if(str[i-j+1]==str[i+j])
23                     cnt++;
24                 else
25                     break;
26             }
27         }
28         printf("%d\n",cnt);
29     }
30     return 0;
31 }

 

posted @ 2014-03-14 21:31  清风旋叶  阅读(177)  评论(0编辑  收藏  举报