PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
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
题意:
输入一个字符串,求该字符串中最长对称子串的长度。
题解:
穷举搜索,既要考虑 baab这种偶数类型的,也要考虑abcba这种技术类型的。
AC代码:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstring>
using namespace std;
string a;
int main(){
getline(cin,a);
int len=a.length();
int mx=;
//先偶数
int r=,l=;
int k;
for(r=;r<len;r++)
{
l=r+;
k=;
int rr=r;
int ll=l;
while(rr>=&&ll<len&&a[rr]==a[ll]){
k+=;
rr--;ll++;
}
mx=max(k,mx);
}
//再奇数
for(r=;r<len;r++)
{
l=r+;
k=;
int rr=r;
int ll=l;
while(rr>=&&ll<len&&a[rr]==a[ll]){
k+=;
rr--;ll++;
}
mx=max(k,mx);
}
cout<<mx<<endl;
return ;
}
PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)的更多相关文章
- 1040 Longest Symmetric String (25分)(dp)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- PAT 甲级 1040 Longest Symmetric String
https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344 Given a string, you ar ...
- 【PAT甲级】1040 Longest Symmetric String (25 分)(cin.getline(s,1007))
题意: 输入一个包含空格的字符串,输出它的最长回文子串的长度. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/std ...
- 1040. Longest Symmetric String (25)
题目链接:http://www.patest.cn/contests/pat-a-practise/1040 题目: 1040. Longest Symmetric String (25) 时间限制 ...
- PAT甲级——A1040 Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- PAT1040 Longest Symmetric String (25分) 中心扩展法+动态规划
题目 Given a string, you are supposed to output the length of the longest symmetric sub-string. For ex ...
- PAT甲题题解-1040. Longest Symmetric String (25)-求最长回文子串
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789177.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT (Advanced Level) 1040. Longest Symmetric String (25)
暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ...
- PAT 1040 Longest Symmetric String[dp][难]
1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...
随机推荐
- 【noi2019集训题1】 脑部进食 期望dp+高斯消元
题目大意:有n个点,m条有向边,每条边上有一个小写字母. 有一个人从1号点开始在这个图上随机游走,游走过程中他会按顺序记录下走过的边上的字符. 如果在某个时刻,他记录下的字符串中,存在一个子序列和S2 ...
- Swagger2 模拟请求头
前几天开发项目的时候,使用了Restful风格的接口.进行开发的时候,模拟请求头,带Token的时候遇到了一些问题.因为Api接口使用Swagger2进行搭建,所以找到了Swagger2 模拟head ...
- [CSS] Change the Alignment of a Single Flexed Item with 'align-self'
Inside of a flexed container, a single item can control its own flex with align-self. The possible v ...
- 【安卓基础】ViewPager2的入门使用
之前的项目中使用过ViewPager,被坑过几次.如果你在RecyclerView中的Item使用ViewPager,你绝对会产生莫名其妙的问题,因为ViewPager在同一界面上不能有两个一样的ID ...
- 010_IAR安装
链接:https://pan.baidu.com/s/14qZh1Gxl32dD2TWdjEYP7Q提取码:yj65 复制这段内容后打开百度网盘手机App,操作更方便哦 里面有安装说明 (一)编辑界面 ...
- hive on spark (spark2.0.0 hive2.3.3)
hive on spark真的很折腾人啊!!!!!!! 一.软件准备阶段 maven3.3.9 spark2.0.0 hive2.3.3 hadoop2.7.6 二.下载源码spark2.0.0,编译 ...
- ES WIndows 安装 ES与ES-head
一.ES的安装 1.到ES官网下载ES 安装ES前,需要安装JDK1.8以上版本 https://www.elastic.co/downloads/elasticsearch 2.解压ES 3.安装E ...
- 如何利用shell或者awk二维数组实现9x9乘法表?
第一种:利用shell for循环来实现. for i in `seq 1 9`do for j in `seq 1 9` do if [ $i -ge $j ] then echo -en &quo ...
- 关于$internalField边界条件【翻译】
翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam-pre-processing/122386-about-internalfi ...
- sonar,jiar,xray,jenkins[cli] [sudoers]
curl -n -X POST http://52.83.39.59:8080'/job/CLA_SSO/buildWithParameters?token=11d710a8eac8012bea28b ...