南阳 132 最长回文子串
来源:互联网 发布:连云港seo公司 编辑:程序博客网 时间:2024/05/31 13:16
#include <stdio.h>#include <string.h>#include <ctype.h>char str[5010];int pos[5010];char ch[5010];int main(){ int i,j,k; int T; int len; int max; int from,to; scanf("%d%*c",&T); //getchar(); while(T--) { memset(str,0,sizeof(str)); memset(pos,0,sizeof(pos)); memset(ch,0,sizeof(ch)); //gets gets(str); len = strlen(str); j = 0; for(i=0; i<len; i++) { if(isalpha(str[i])) { ch[j] = toupper(str[i]); pos[j++] = i; } } len = j; j = 0; max = -1; for(i=0; i<len; i++) { //奇数 for(j=0; i+j<len&&i-j>=0; j++) { if(ch[i-j]!=ch[i+j]) break; if(2*j+1>max) { max = 2*j+1; from = i-j; to = i+j; } } //偶数 for(j=0; i+j+1<len&&i-j>=0; j++) { if(ch[i-j]!=ch[i+j+1]) break; if(2*j+2>max) { max = 2*j+2; from = i-j; to = i+j+1; } } } for(i=pos[from]; i<=pos[to]; i++) { putchar(str[i]); } putchar('\n'); } return 0;}
0 0
- 南阳 132 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- PHP foreach数组循环的一些问题
- 深入理解C++的动态绑定和静态绑定
- 01-Linux-Linux系统安装
- 南阳 658 字符串右移
- GitHub使用
- 南阳 132 最长回文子串
- 黑马程序员-重要代码记录Part1(end)
- Centos 安装中文 输入法
- DBMS_UTILITY.get_time——比较时间差
- 最常用的设计模式---装饰者模式(C++实现)
- 南阳 86 找球号(一)
- winform 中 treeview 的根节点与子节点的同步问题
- 主题:如何彻底删除流氓软件“快盒应用”
- poj 3253 Fence Repair