GPLT L2-008. 最长对称子串
来源:互联网 发布:lol英雄详细数据 编辑:程序博客网 时间:2024/04/25 13:44
题目:最长对称子串
思路:枚举每个位置,从每个位置的左右同时开始进行查找相等累计个数,分奇数和偶数俩种情况,筛选最大值即可。
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ char str[1005]; while(gets(str)!=NULL){ int len = strlen(str),l,r,lcnt,rcnt,ans = 0; for(int i=0;i<len;i++){ l = i-1;r = i+1;lcnt = 1;//奇数情况 while(str[l] == str[r] && l>=0 && r<len){l--;r++;lcnt+=2;} l = i;r = i+1;rcnt = 0;//偶数情况 while(str[l] == str[r] && l>=0 && r<len){l--;r++;rcnt+=2;} ans = max(ans,max(lcnt,rcnt)); } printf("%d\n",ans); } return 0;}
0 0
- GPLT L2-008. 最长对称子串
- L2-008. 最长对称子串-PAT团体程序设计天梯赛GPLT
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- L2-008. 最长对称子串
- Nginx+IIS+Redis 处理Session共享问题 2
- HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法
- CSDN博客积分规则
- 文章标题
- Redis之——主从配置详解
- GPLT L2-008. 最长对称子串
- Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]
- 漫步数理统计七——随机变量(上)
- 使用Mono.xml解析xml表
- HDUoj 4278 Faulty Odometer (数学
- 科锐课堂笔记:2017/3/13 宏与预处理指令
- Gson 解析Json数据
- 图像绕某点旋转的矩阵的确定(getRotationMatrix2D函数解析)
- MySQL5.6.11安装步骤