【PAT甲级】1040 Longest Symmetric String (25 分)(cin.getline(s,1007))
题意:
输入一个包含空格的字符串,输出它的最长回文子串的长度。
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))的更多相关文章
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- 1040 Longest Symmetric String (25分)(dp)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- PAT 甲级 1040 Longest Symmetric String
https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344 Given a string, you ar ...
- 1040. Longest Symmetric String (25)
题目链接:http://www.patest.cn/contests/pat-a-practise/1040 题目: 1040. Longest Symmetric String (25) 时间限制 ...
- PAT甲级——A1040 Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- PAT1040 Longest Symmetric String (25分) 中心扩展法+动态规划
题目 Given a string, you are supposed to output the length of the longest symmetric sub-string. For ex ...
- PAT甲题题解-1040. Longest Symmetric String (25)-求最长回文子串
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789177.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT (Advanced Level) 1040. Longest Symmetric String (25)
暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ...
- 【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))
题意: 输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写). AAAAAccepted code: #define HAVE_STRUCT ...
随机推荐
- OSI七层协议详解
一.简介 开放系统互连参考模型 (Open System Interconnect 简称OSI)是国际标准化组织(ISO)和国际电报电话咨询委员会(CCITT)联合制定的开放系统互连参考模型,为开放式 ...
- Linux 中查看可用的网络接口
目录 Linux 中查看可用的网络接口 在 Linux 中找到可用的网络接口 title: Linux 中查看可用的网络接口 date: 2020/2/25 16:56:36 toc: true -- ...
- 隐藏wordpress版本信息
在主题中的functions.php中添加如下代码: remove_action( 'wp_head', 'wp_generator');
- Oracle中的数据迁移到Mysql数据库中的方式Navicat premium工具
1.安装 Navicat premium工具 2.破解 Navicat premium工具 3.连接需要相互迁移的两个库Mysql和Oracle(可以是远程的或者本机的数据库都是可以的) 4.连接上之 ...
- jquery点击添加样式,再次点击移除样式
$("#divSetting").on("click", function () { $(this).toggleClass("open") ...
- linux安装tomcat步骤
2.1 查看当前系统是否安装过该软件,如果安装过则下载 rpm –qa | grep –i tomcat rpm –e --nodeps 程序名称2.2上传2.3创建tomcat的安装路径 mkdir ...
- Linux实现树莓派3B的国密SM9算法交叉编译——(二)miracl库的测试与静态库的生成
先参考这篇文章 Linux实现树莓派3B的国密SM9算法交叉编译——(一)环境部署.简单测试与eclipse工程项目测试 部署好环境,并简单测试交叉编译环境是否安装成功,最后实现在Eclipse上进行 ...
- Go第三方库之tail
Tail Demo // tail.TailFile()函数开启goroutine去读取文件,通过channel格式的t.lines传递内容. t, err := tail.TailFile(&quo ...
- 多种方式实现平均分栏布局(有间距)div平分行宽
以下例子基于分四栏+栏间有间距的例子分析 效果图: html代码: <div class="buy-one-buy"> <h3>淘一淘</h3> ...
- jmeter实现对Oracle数据库的操作
实现目的 有时候,根据业务需要,可能需要直接对数据库进行性能测试,此时可利用jmeter对Oracle.MySQL等数据库进行相关测试. 脚本实现 添加JDBC Connection Configur ...