字符串中对称子串的个数

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 }

 

转载于:https://www.cnblogs.com/lyf123456/p/3601318.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值