寻找最长回文子串
来源:互联网 发布:百度软件中心开发者 编辑:程序博客网 时间:2024/05/17 22:39
描述:从一个字符串中查找最长的回文子串,并输出该子串。
样例输入:dgaabcddcbadfabcdefghijkkjihgfedcbagaaabbccddddccbbaaaf
样例输出:aaabbccddddccbbaaa
#include <string>#include <iostream>using namespace std;static string FindSymmetry(string str){for (int i = str.length() - 1; i >= 0; i--){for (int j = 0; j < i; j++){string temp = str.substr(j, i - j+1);int k = 0;for (; k < temp.length() / 2; k++){if (temp[k] != temp[temp.length() - k - 1])break;}if (k == temp.length() / 2){return temp;}}}return "";}int main(){string str = "dgaabcddcbadfabcdefghijkkjihgfedcbagaaabbccddddccbbaaaf";cout<<FindSymmetry(str)<<endl;return 0;}
阅读全文
0 0
- 寻找最长回文子串
- 寻找最长回文子串
- 寻找最长回文子串 Longest Palindrome DP解法
- 寻找最长回文子串Manacher算法学习笔记
- [Leetcode #5]Longest Palindromic Substring 寻找最长回文子串
- leetcode-5. Longest Palindromic Substring(寻找最长回文子串)
- python实现寻找最长回文子序列
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串
- 贪心问题 B: 出租车费
- Servlet
- Polynomial operation with C++
- js--8.交互方式
- 【opencv学习之十三】opencv阈值分割threshold函数
- 寻找最长回文子串
- bzoj1370 [Baltic2003]Gang团伙
- java.sql.SQLException: The Network Adapter could not establish the connection
- VS Code中转换大小写功能
- Linux安装教程--Ubuntu使用简单手册之安装篇
- GET、POST和HEAD的区别?
- Leetcode之Valid Triangle Number 问题
- 【C++】浅拷贝和深拷贝以及怎样实现一个简单的string类!!!
- 训练集---训练赛14