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. python学习之flask接口开发,环境变量扩展,网络编程requests

    python基础 flask之mock接口 所谓mock接口,其实就是我们在正式接口还没联调或者是测试接口没有正式使用时,自己创建一个模拟接口,来供项目暂时打通功能或者测试流程梳理的桥梁,而我们这儿使 ...

  2. 《AlwaysRun团队》第三次作业:团队项目的原型设计

    <AlwaysRun团队>第三次作业:团队项目的原型设计 项目 内容 这个作业属于哪个课程 [任课教师博客主页链接](https://home.cnblogs.com/u/nwnu-dai ...

  3. 17 webpack中babel的配置——静态属性与实例属性

    // class关键字,是ES6中提供的新语法,是用来实现ES6中面向对象编程的方式 class Person{ // 使用static关键字,可以定义静态属性 // 所谓的静态属性,就是可以直接通过 ...

  4. Python+request 使用pymysql连接数据库mysql的操作《十》

    使用指南.pymysql支持python2.7同时也支持python3.x.当前我用的是python2.7.所以过断选择了pymysql的使用,这里注意几点.一般我们连接数据库为了安全起见,都会要求按 ...

  5. 微信小程序导入Vant报错

    作者:如也_d1c0链接:https://www.jianshu.com/p/0d2332984f8c来源:简书简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处. 先放出来Vant ...

  6. 04_Tutorial 4: Authentication & Permissions 认证和权限

    1.认证和权限 0.文档 https://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/ https: ...

  7. Navicat连接Oracle报ORA-12737错误

    替换oci.dll 文件分享百度网盘:链接:https://pan.baidu.com/s/1wayojGlKcgdMRZTvBqAUgw 密码:3d6j 把下载的文件放到Navicat文件夹里,然后 ...

  8. 1069 The Black Hole of Numbers(20 分)

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  9. macOs下安装Android SDK

    首先下载 Android SDK for mac 配置安装 1.进入存放 android-sdk-macosx 的目录,然后输入./android sdk就可以调出SDK Manager的图形界面 A ...

  10. 结构体与C++sort()函数的用法

    C++sort()函数的用法 先看道题(本题来自http://codeup.cn/第26099): 题目描述 [问题描述] 高三全省联合模拟考试刚刚结束,经过各科老师的努力,各个学科的改卷工作终于结束 ...