题意:

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

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. Django的安装、使用详解、自动化测试应用以及程序打包

    1.Django的安装 pip install Django 验证 Django 是否能被 Python 识别 >>> import django >>> prin ...

  2. Makefile export

    1) 1.在(parent,上层的)makefile中export出来变量,子makefile(sub make)中,是可以访问的. 2. 而同一级别的makefile(可通过makefile中内置变 ...

  3. IDEA格式化代码快捷键失灵原因

    网易云音乐快捷键与IDEA快捷键冲突了!!!!!!!坑爹

  4. GitHub网页版基本操作

    创建存储库 登录GitHub进入主页,点击头像左边的加号,创建存储库 填写存储库名称.描述,根据需求设置其他选项.点击“Create repository”按钮 创建分支 打开之前创建好的存储库,点击 ...

  5. 吴裕雄 python 机器学习——KNN回归KNeighborsRegressor模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import neighbors, datasets from skle ...

  6. windows 动态库导出

    以下内容来自博客:https://blog.csdn.net/fengbingchun/article/details/78825004 __declspec是Microsoft VC中专用的关键字, ...

  7. Python - Git for windows 下使用 交互式命令行

    1. 概述 尝试在 windows 环境的 git 命令行使用 python3 的交互模式 2. 环境 OS win10 1905 git 2.20.1 mintty 2.9.4 python 3.7 ...

  8. 输入两个正整数num1、num2,计算并输出它们的和、差、积、整数商和余数

    课本例题 /*输入两个正整数num1.num2,计算并输出它们的和.差.积.整数商和余数.*/ #include<stdio.h> int main() { int num1, num2; ...

  9. hadoop学习笔记(五)hadoop伪分布式集群的搭建

    本文原创,如需转载,请注明作者和原文链接 1.集群搭建的前期准备   见      搭建分布式hadoop环境的前期准备---需要检查的几个点 2.解压tar.gz包 [root@node01 ~]# ...

  10. Kali2.0中peda与pwntools的安装

    MarkdownPad Document *:first-child { margin-top: 0 !important; } body>*:last-child { margin-botto ...