https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344

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 <bits/stdc++.h>
using namespace std; string s; int main() {
getline(cin, s);
int len = s.length(); int ans = 1, cnt = 1, out = 1;
for(int i = 0; i < len; i ++) {
int st = i, en = i;
while(st >= 0 && en < len && s[st] == s[en]) {
st --;
en ++;
}
ans = max(ans, en - st + 1);
} for(int i = 0; i < len - 1; i ++) {
int stt = i, enn = i + 1;
while(stt >= 0 && enn < len && s[stt] == s[enn]) {
stt --;
enn ++;
}
cnt = max(cnt, enn - stt + 1);
} out = max(ans, cnt);
printf("%d\n", out - 2);
return 0;
}

  这个题好像很久之前就开过来一直没写出来 可能是猪脑子吧

PAT 甲级 1040 Longest Symmetric String的更多相关文章

  1. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

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

  2. PAT甲级——A1040 Longest Symmetric String

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

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

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

  4. 1040. Longest Symmetric String (25)

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

  5. PTA (Advanced Level) 1040 Longest Symmetric String

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

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

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

  7. 1040 Longest Symmetric String

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

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

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

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

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

随机推荐

  1. CentOS 7.2搭建xl2tp服务器

    ## 1.下载xl2tpd.tar.gz源码包 ```wget http://pkgs.fedoraproject.org/repo/pkgs/xl2tpd/xl2tpd-1.3.8.tar.gz/d ...

  2. (补题 杭电 1008)Elevator

    Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. 一个C语言萌新的学习之旅(持续更新中...)

    三:计算和类型 一:隐式转换和显示转换 隐式转换:隐式转换指的是自动类型转换,自动向精确,大范围类型转换. 显示转换:例如:(int)3.5*6.0f=18.0f (int)(3.5*6.0f)=21 ...

  4. node.js 监听message事件 message字符串丢失信息

    const dgram = require("dgram"); const server = dgram.createSocket("udp4"); serve ...

  5. 【8086汇编-Day2】dosbox实验环境配置及测试

    我学习汇编用的是王爽的<汇编语言>第三版,书中是以8086处理器为例,是工作在实模式下的,而当下的个人电脑处理器都是工作在保护模式下的.所以需要一个虚拟的工作在实模式下的处理器,这里主要用 ...

  6. Reflow & Repaint

    http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/ http://segmentfault.com/a/1190000002 ...

  7. 20155211 2016-2017-2 《Java程序设计》第四周学习总结

    20155211 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 这周的内容感觉较上周相比难度增加 教材学习中的问题和解决过程 刚开始学习第六章的时候的时候敲 ...

  8. Oracle下建立dblink时的权限问题

    如果用普通用户,如果没授权,是无法建立dblink的: [oracle@oracle000 ~]$ sqlplus gao/gao lines) SQL Production :: Copyright ...

  9. [CF888E] Maximum Subsequence 序列分治

    早期作品,不喜轻喷. LG传送门 序列分治板子题. 切这道题用了好长时间,所以想发篇题解作为纪念 . 首先,我们认真观察题目数据(面向数据做题是个好习惯),发现题目的\(n\)竟然只有\(35\),我 ...

  10. HBase第一章 安装 HMaster 主备

    1.集群环境 Hadoop HA 集群规划 hadoop1 cluster1 nameNode  HMaster hadoop2 cluster1 nameNodeStandby ZooKeeper ...