首页 > 其他 > 详细

字符串中对称子串的个数

时间:2014-03-15 01:59:14      阅读:512      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
 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 }
bubuko.com,布布扣

字符串中对称子串的个数,布布扣,bubuko.com

字符串中对称子串的个数

原文:http://www.cnblogs.com/lyf123456/p/3601318.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!