题意:

输入一个包含空格的字符串,输出它的最长回文子串的长度。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
char s[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin.getline(s+,);
int ans=;
int cnt=strlen(s+);
if(cnt)
ans=;
for(int i=;i<=cnt;++i){
int l=i-,r=i+;
while(){
if(l<||r>cnt)
break;
if(s[l]==s[r]){
ans=max(ans,r-l+);
--l;
++r;
}
else
break;
}
l=i,r=i+;
while(){
if(l<||r>cnt)
break;
if(s[l]==s[r]){
ans=max(ans,r-l+);
--l;
++r;
}
else
break;
}
}
cout<<ans;
return ;
}

【PAT甲级】1040 Longest Symmetric String (25 分)(cin.getline(s,1007))的更多相关文章

  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. 1040 Longest Symmetric String (25分)(dp)

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

  3. PAT 甲级 1040 Longest Symmetric String

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

  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甲级】1071 Speech Patterns (25 分)(getline(cin,x))

    题意: 输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写). AAAAAccepted code: #define HAVE_STRUCT ...

随机推荐

  1. linux deploy---旧手机变废为宝

    前几天朋友送了我一部红米Note 1s,本来不想要,转念一想,不要白不要,就收了. 拿到之后我就想,这么一个1+8的手机能做什么呢? 翻遍了CSDN和简书,找到了一个性价比不错的方法:给旧手机装上一个 ...

  2. 通过scrapy,从模拟登录开始爬取知乎的问答数据

    这篇文章将讲解如何爬取知乎上面的问答数据. 首先,我们需要知道,想要爬取知乎上面的数据,第一步肯定是登录,所以我们先介绍一下模拟登录: 先说一下我的思路: 1.首先我们需要控制登录的入口,重写star ...

  3. 【转载】Java反射机制详解

    转自:http://baike.xsoftlab.net/view/209.html#3_8 1反射机制是什么 反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对 ...

  4. codeforces 1204C Anna, Svyatoslav and Maps(floyd+dp)

    题目链接:http://codeforces.com/problemset/problem/1204/C 给定一组序列,P1,P2,P3...Pm,这是一组合法路径的序列,即任意的Pi和Pi+1之间有 ...

  5. 第二十篇 Linux条件测试语句相关知识点介绍

      条件测试语句的格式如下: [ 条件表达式 ]        # 条件表达式两侧各有一个空格 按测试对象不同,条件测试语句共分为4中类型: 文件测试语句 逻辑测试语句 整数值比较语句 字符串比较语句 ...

  6. pods " xxxx" not found错误

    pods " xxxx" not found错误 待办 https://linuxacademy.com/community/show/29447-pod-is-not-found ...

  7. php 填写pdf 表单

    最近接到新的任务,要求把pdf的文档,编辑后发邮件 首先pdf表单提交,需要用到这个东西pdftk,GitHub地址:https://github.com/mikehaertl/php-pdftk 首 ...

  8. C#连接SQL Server数据库(二)

    执行SQL语句:Command对象 1.Command对象概述   Command对象是一个数据命令对象,主要功能是向数据库发送查询.更新.删除.修改操作的SQL语句.Command对象主要有以下几种 ...

  9. Vacation

    题目看上去倒是蛮复杂的样子嘞!

  10. cmake 单个目录多个文件的情况

    参考:https://www.hahack.com/codes/cmake/# 源文件一共有三个:main.cpp.MathFunctions.h.MathFunctions.cpp 文件内容分别如下 ...