当前位置:网站首页>1040 Longest Symmetric String
1040 Longest Symmetric String
2022-07-05 05:51:00 【Brosto_Cloud】
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 <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
string s;
int ans, maxx = -1;
getline(cin, s);
for (int i = 0; i < s.size(); i++) { //奇数情况
int j = i - 1, k = i + 1;
ans = 1;
while (j >= 0 && k < s.size() && s[j] == s[k]) {
ans += 2;
j--;
k++;
}
maxx = max(maxx, ans);
}
for (int i = 0; i < s.size(); i++) {
int j = i, k = i + 1;
ans = 0;
while (j >= 0 && k < s.size() && s[j] == s[k]) {
ans += 2;
j--;
k++;
}
maxx = max(maxx, ans);
}
cout << maxx;
return 0;
}
边栏推荐
- leetcode-1200:最小绝对差
- Individual game 12
- 【实战技能】如何做好技术培训?
- How to adjust bugs in general projects ----- take you through the whole process by hand
- Educational codeforces round 109 (rated for Div. 2) C. robot collisions D. armchairs
- 2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
- wordpress切换页面,域名变回了IP地址
- API related to TCP connection
- 6. Logistic model
- Wazuh开源主机安全解决方案的简介与使用体验
猜你喜欢

数据可视化图表总结(二)

EOJ 2021.10 E. XOR tree

Sword finger offer 09 Implementing queues with two stacks

剑指 Offer 35.复杂链表的复制

7. Processing the input of multidimensional features

【Jailhouse 文章】Look Mum, no VM Exits

AtCoder Grand Contest 013 E - Placing Squares

Smart construction site "hydropower energy consumption online monitoring system"
![[jailhouse article] look mum, no VM exits](/img/fe/87e0851d243f14dff96ef1bc350e50.png)
[jailhouse article] look mum, no VM exits

API related to TCP connection
随机推荐
Sword finger offer 04 Search in two-dimensional array
R language [import and export of dataset]
Spark中groupByKey() 和 reduceByKey() 和combineByKey()
[jailhouse article] performance measurements for hypervisors on embedded ARM processors
Daily question 2013 Detect square
【Rust 笔记】14-集合(上)
Control Unit 控制部件
常见的最优化方法
2022年貴州省職業院校技能大賽中職組網絡安全賽項規程
A problem and solution of recording QT memory leakage
Dynamic planning solution ideas and summary (30000 words)
【云原生】微服务之Feign自定义配置的记录
After setting up the database and website When you open the app for testing, it shows that the server is being maintained
One question per day 1765 The highest point in the map
剑指 Offer 05. 替换空格
2017 USP Try-outs C. Coprimes
Detailed explanation of expression (csp-j 2021 expr) topic
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
Personal developed penetration testing tool Satania v1.2 update
Smart construction site "hydropower energy consumption online monitoring system"