PAT甲级 1040
来源:互联网 发布:装修软件哪个好 编辑:程序博客网 时间:2024/05/29 19:05
Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given “Is PAT&TAP symmetric?”, the longest symmetric sub-string is “s PAT&TAP s”, hence you must output 11.
Input Specification:
Each input file contains one test case which gives a non-empty string of length no more than 1000.
Output Specification:
For each test case, simply print the maximum length in a line.
Sample Input:
Is PAT&TAP symmetric?
Sample Output:
11
- 注意一个奇对称和一个偶对称。
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;const int maxn=1000+1;char input[maxn];bool pointInInterval(int pos){ if(pos>=0 && pos<strlen(input))return true; return false;}int getLengthByCurPos(int l,int r){ while(pointInInterval(l) && pointInInterval(r) && input[l]==input[r]){ --l,++r; } return r-l-1;}int main(){ gets(input); int rst=0; for(int i=0;i<strlen(input);i++){ rst=max(rst,getLengthByCurPos(i,i)); rst=max(rst,getLengthByCurPos(i,i+1)); } printf("%d",rst);}
阅读全文
0 0
- PAT(甲级)1040
- 浙大PAT甲级 1040
- PAT甲级1040
- PAT甲级 1040
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- Docker中实现redis分片
- HTTP协议知多少-关于http1.x、http2、SPDY的相关知识
- Calendar 获取下周一的日期
- android不让程序显示在最近程序列表中
- java实现通过快速排序来查找数组中第n大的元素
- PAT甲级 1040
- 606. Construct String from Binary Tree
- Java包装类
- 【Redis笔记】5.List(L)
- hdu 3572(板子
- 端口转发和SOCKS代理
- 添加到网站上的百度地图,标注图标不显示
- 对本地文件进行操作File
- EasyAR 初学者入门指南(1)---显示模型