PAT 甲级 1040 Longest Symmetric String
https://pintia.cn/problem-sets/994805342720868352/problems/994805446102073344
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?
, the longest symmetric sub-string is s PAT&TAP s
, hence you must output 11
.
Input Specification:
Each input file contains one test case which gives a non-empty string of length no more than 1000.
Output Specification:
For each test case, simply print the maximum length in a line.
Sample Input:
Is PAT&TAP symmetric?
Sample Output:
11
代码:
#include <bits/stdc++.h>
using namespace std; string s; int main() {
getline(cin, s);
int len = s.length(); int ans = 1, cnt = 1, out = 1;
for(int i = 0; i < len; i ++) {
int st = i, en = i;
while(st >= 0 && en < len && s[st] == s[en]) {
st --;
en ++;
}
ans = max(ans, en - st + 1);
} for(int i = 0; i < len - 1; i ++) {
int stt = i, enn = i + 1;
while(stt >= 0 && enn < len && s[stt] == s[enn]) {
stt --;
enn ++;
}
cnt = max(cnt, enn - stt + 1);
} out = max(ans, cnt);
printf("%d\n", out - 2);
return 0;
}
这个题好像很久之前就开过来一直没写出来 可能是猪脑子吧
PAT 甲级 1040 Longest Symmetric String的更多相关文章
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- PAT甲级——A1040 Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- PAT 1040 Longest Symmetric String[dp][难]
1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...
- 1040. Longest Symmetric String (25)
题目链接:http://www.patest.cn/contests/pat-a-practise/1040 题目: 1040. Longest Symmetric String (25) 时间限制 ...
- PTA (Advanced Level) 1040 Longest Symmetric String
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the lo ...
- 1040 Longest Symmetric String (25分)(dp)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- 1040 Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...
- 【PAT甲级】1040 Longest Symmetric String (25 分)(cin.getline(s,1007))
题意: 输入一个包含空格的字符串,输出它的最长回文子串的长度. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/std ...
- PAT甲题题解-1040. Longest Symmetric String (25)-求最长回文子串
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789177.html特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- 有关javaEE及WebGIS的一些地址
jdk:https://www.oracle.com/index.html eclipse:https://www.eclipse.org spring:http://repo.springsourc ...
- React with webpack
//entry.js require("!style!css!./style.css"); require("./hello.jsx"); // documen ...
- 20155203 2016-2017-3 《Java程序设计》第4周学习总结
20155203 2016-2017-3 <Java程序设计>第4周学习总结 教材学习内容总结 1.父类和子类类似于集合和元素,不同的地方是子类可以拓展(extends)父类之外的方法. ...
- 20155302 2016-2017-2 《Java程序设计》第4周总结
20155302 2016-2017-2 <Java程序设计>第4周学习总结 教材学习内容总结 有关类的继承的理解:类实现继承的格式:class 子类名 extends 父类名 类的继承有 ...
- 2017-2018-1 20155338《信息安全技术》实验二——Windows口令破解
2017-2018-1 20155338<信息安全技术>实验二--Windows口令破解 一.试验环境 系统环境:Windows 实验工具: LC5 SuperDic 二.实验内容及要求 ...
- 20145234黄斐《网络对抗技术》实验五,MSF基础应用
MSF的六种模块 渗透攻击模块(Exploit Modules)渗透攻击是指由攻击者或渗透测试者利用一个系统.应用或服务中的==安全漏洞==,所进行的攻击行为. 辅助模块(Auxiliary Modu ...
- [2016北京集训测试赛5]azelso-[概率/期望dp]
Description Solution 感谢大佬的博客https://www.cnblogs.com/ywwyww/p/8511141.html 定义dp[i]为[p[i],p[i+1])的期望经过 ...
- 优步UBER司机全国各地奖励政策汇总:北京、上海、广州、深圳、佛山、天津、南京、武汉、成都、重庆、济南、西安、宁波、青岛、长沙、苏州
Uber当周奖励政策 当前奖励包括:高峰翻倍奖励.行程奖励.金牌司机奖励 获得任何奖励的前提条件: 当周评分高于4.7分,当周成单率高于45%,且当周完成至少5单(含5单) 滴滴快车单单2.5倍,注册 ...
- 2762 helloparty·开车
2762 helloparty·开车 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description hellokitty的一个朋友要来他家,但是 ...
- Zabbix学习之路(六)TCP状态监控
TCP状态监控 Tcp的连接状态对于我们web服务器来说是至关重要的,尤其是并发量ESTAB:或者是syn_recv值,假如这个值比较大的话我们可以认为是不是受到了***,或是是time_wait值比 ...