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 分)(字符串最长对称字串,遍历)的更多相关文章

  1. 1040 Longest Symmetric String (25分)(dp)

    Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...

  2. PAT 甲级 1040 Longest Symmetric String

    https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344 Given a string, you ar ...

  3. 【PAT甲级】1040 Longest Symmetric String (25 分)(cin.getline(s,1007))

    题意: 输入一个包含空格的字符串,输出它的最长回文子串的长度. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/std ...

  4. 1040. Longest Symmetric String (25)

    题目链接:http://www.patest.cn/contests/pat-a-practise/1040 题目: 1040. Longest Symmetric String (25) 时间限制 ...

  5. PAT甲级——A1040 Longest Symmetric String

    Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...

  6. PAT1040 Longest Symmetric String (25分) 中心扩展法+动态规划

    题目 Given a string, you are supposed to output the length of the longest symmetric sub-string. For ex ...

  7. PAT甲题题解-1040. Longest Symmetric String (25)-求最长回文子串

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789177.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  8. PAT (Advanced Level) 1040. Longest Symmetric String (25)

    暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ...

  9. PAT 1040 Longest Symmetric String[dp][难]

    1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...

随机推荐

  1. css完结篇

    1.如何让一个绝对定位的盒子居中 left:50%; margin-left:-宽度的一半; 2.固定定位 position:fixed; 1.脱标 参考点:浏览器左上角 作用:固定导航栏,返回顶部, ...

  2. 【转】用 Consul 来做服务注册与服务发现

    原文:https://segmentfault.com/a/1190000018731395?utm_source=tag-newest ------------------------------- ...

  3. vue+webpack4 脚手架搭建

    1, vue 中 h => h(App) 的含义: //render: h => h(App) 是下面内容的缩写: render: function (createElement) { r ...

  4. JQgrid处理json数据

    jqGrid 实例中文版网址:http://blog.mn886.net/jqGrid/国外官网:http://www.trirand.com/blog/jqgrid/jqgrid.html http ...

  5. python多线程实现ping多个ip

    #!/usr/bin/env python # -*- coding:utf-8 -*- import subprocess import logging import datetime import ...

  6. vue 仿新闻项目笔记

    1.main.js: import filters from 'XXX' Object.keys(filters).forEach(key => Vue.filter(key, filters[ ...

  7. Spring MVC 学习笔记(一)

    • 1.SpringMVC概述 • 2.SpringMVC的HelloWorld • 3.使用@RequestMapping映射请求 • 4.映射请求参数&请求头 • 5.处理模型数据 • 6 ...

  8. Jfinal undertow本地运行加载静态文件

    undertow部署文档中可配置静态资源也可以添加磁盘目录作为项目中得静态文件访问 undertow.resourcePath = src/main/webapp, D:/static 这样配置就可以 ...

  9. Vue项目中v-bind动态绑定src路径不成功

    问题: 在做Vue项目的时候,由于项目需求,需要动态绑定img的src时,突然发现如果说是直接请求后台接口的图片地址就能显示, 但是直接动态绑定img的src的图片的相对路径或者是绝对路径的时候,图片 ...

  10. 45、[源码]-Spring容器创建-执行BeanFactoryPostProcessor

    45.[源码]-Spring容器创建-执行BeanFactoryPostProcessor 5.invokeBeanFactoryPostProcessors(beanFactory);执行BeanF ...