题意:

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

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. python-PIL-16bit-灰度图像生成-tiff

    import numpy from PIL import Image a=numpy.array(numpy.uint16([[12,23,34],[123,213,22]])) im=Image.f ...

  2. 线性筛-三合一,强大O(n)

    校内CJOJ2395by Jesse Liu 筛法三合一 Euler.Möbius.Prime函数 基于数论的积性函数 gcd(a,b)=1  则  ƒ(ab)=ƒ(a)ƒ(b) #include & ...

  3. 有源汇有上下界最小流 (ZQU 1592)

    这道题跟求最大流的时候差不多. 都是先构造可行流,然后判断是否可行, 可行的话,就利用残余流量,构造从汇点t跑到源点s的最大流, 如何求出答案呢. 在第一次求可行流的dinic后,跟求最大流的时候一样 ...

  4. python字典里面列表排序

    #coding=utf8 #获取到的数据库ip,和负载数据,需要按照负载情况排序 a={u'1.8.1.14': [379, 368, 361, 358, 1363], u'9.2.4.3': [42 ...

  5. MySQL 避免使用字符串类型作为标识列

    避免使用字符串类型作为标识列: 消耗空间. 比数字类型慢(MyISAM 中对字符串使用压缩索引,查询会慢). 对于 MD5().UUID() 生成的随机字符串,这些值会分布在很大的空间内,导致 ins ...

  6. linux安装、使用优化、常用软件

    定制自己的ubuntu桌面系统 一.安装ubuntu 1.下载ubuntu镜像Iso文件 ubuntu官网下载:https://cn.ubuntu.com/download 2.u盘写入 (1)下载U ...

  7. web应用程序上传文件 超过了最大请求长度

    具体问题如下图 具体问题描述:在web应用程序中,上传了200M的文件,出现了如上图的问题,上传较小文件的时候,没有任何的问题.但是,测试的能力,不容小觑,真真的会测试的很全面.测试到了这个问题,好吧 ...

  8. linux下windows访问samba服务器

    今天学习windows如何访问linux的共享文件. 开通samba服务,首先需要在linux下安装samba程序包,又再次使用光盘镜像挂载: [root@localhost home]# mount ...

  9. 201771010135 杨蓉庆/张燕/杨玲《面对对象程序设计(java)》第十四周学习总结

    1.实验目的与要求 (1) 掌握GUI布局管理器用法: (2) 掌握各类Java Swing组件用途及常用API 一.理论知识  Swing和MVC设计模式 (1)设计模式(Design patte ...

  10. java篇 之 抽象

    Abstract(抽象): Public abstract void work();  <==> public void work(){ }     抽象方法,存在于抽象类中, 提供一个方 ...