题意:

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

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. Java正则表达式提取String字符串中的IP地址

    /** * 正则提前字符串中的IP地址 * @param ipString * @return */ public static List<String> getIps(String ip ...

  2. ubuntu14.04安装google chrome

    安装好Ubuntu14.04之后安装google chrome浏览器 1.按下 Ctrl + Alt + t 键盘组合键,启动终端 2.在终端中,输入以下命令 (将下载源加入到系统的源列表.命令的反馈 ...

  3. Abp.core中在应用层获取HttpContext对象

    实际IHttpContextAccessor对象已经在底层实现了自动的依赖注入,只需要在应用层引入Microsoft.AspNetCore.Http,然后在构造函数中依赖注入即可. /// <s ...

  4. numpy (1.16.4) has the default value of allow_pickle as False.

    My version of numpy (1.16.4) has the default value of allow_pickle as False. numpy版本是1.16.4,allow_pi ...

  5. springboot @ComponentScan注解

    @ComponentScan 告诉Spring从哪里找到bean. 如果你的其他包都在@SpringBootApplication注解的启动类所在的包及其下级包,则你什么都不用做,SpringBoot ...

  6. 概率DP (大概是最入门的题了) lightoj 1248

    有一个骰子,n个面,问所有面都被摇出的期望. 转自**的博客,  因为概率是(n-k)/n  所以期望次数是1/(前面这个数) #include<cstdio> #include<a ...

  7. Nuxt配置动态路由以及参数校验

    动态路由就是带参数的路由.比如我们商品列表里很多商品详细页,这时候就需要动态路由的帮助了. 比如我们新建一个commodity文件夹,新建一个index.vue 文件,然后新建一个_id.vue (以 ...

  8. Linux - gitlab的命令

    启动 sudo gitlab-ctl start 关闭 sudo gitlab-ctl stop 重新加载配置文件 sudo gitlab-ctl reconfigure 在本地初始化一个本地仓库 g ...

  9. SpringMVC的三种处理器适配器

    SpringMVC具有三种处理器适配器,他们分别是BeanNameUrlHandlerMapping.SimpleControllerHandlerAdapter.ControllerClassNam ...

  10. RPA_播放语音

    验证码识别 from rpa.captcha.captcha import Captcha c = Captcha() log.info(tmp_file_path) captcha_result = ...