- 浏览: 36655 次
- 性别:
- 来自: 杭州
最新评论
求最长回文子串
#include <iostream> #include <string> #include <iomanip> using namespace std; int main() { string a; getline(cin,a); int max = 0; int length = a.size(); for(int i = 0; i < length; i++) { for(int j = 0; i - j >= 0 && i + j < length; j++) { if(a[i-j] != a[i+j]) { break; } if(max < 2*j + 1) { max = 2*j + 1; } } for(int j = 0; i - j >= 0 && i+j+1 < length; j++) { if(a[i-j] != a[i+j+1]) { break; } if(max < 2*j + 2) { max = 2*j+2; } } } cout<<max<<endl; return 0; }
发表评论
-
PAT1013 Battle Over Cities
2012-11-29 23:59 773Sample Input 3 2 3 1 2 1 3 ... -
PAT1003 Emergency
2012-11-29 23:46 662Sample Input 5 6 0 2 1 2 1 ... -
PAT1041 Be Unique
2012-11-23 23:43 760找出只出现过一次的数,用各种排序必然超时,需要用数组做hash ... -
PAT1042 Shuffling Machine
2012-11-23 23:42 733扑克洗牌 #include < ... -
PAT1036 Boys vs Girls
2012-11-23 23:41 716Sample Input 1: 3 Joe M Mat ... -
PAT1035 Password
2012-11-23 23:40 617Sample Input 1: 3 Team0000 ... -
PAT1031 Hello World for U
2012-11-22 23:54 656Sample Input: helloworld! S ... -
PAT1029 Median
2012-11-22 23:54 651用标准库的排序全部超时,需要自己实现,另外还不能用cin co ... -
PAT1028 List Sorting
2012-11-22 23:53 808用vector最后一个用例超时了。。。 Sample ... -
PAT1027 Colors in Mars
2012-11-22 23:52 623Sample Input 15 43 71 Samp ... -
PAT1025 PAT Ranking
2012-11-22 23:51 772Sample Input: 2 5 123456789 ... -
PAT1023 Have Fun with Numbers
2012-11-21 23:55 687大数的相加 比较两个字符串中字符完全相同 Sa ... -
PAT1020 Tree Traversals
2012-11-21 23:54 653已知中序遍历 后序遍历,求层次遍历 Sample In ... -
PAT1019 General Palindromic Number
2012-11-21 23:53 537十进制转任意进制,并比较是否是回文数 Sample I ... -
PAT1037 Magic Coupon
2012-11-21 15:46 664Sample Input: 4 1 2 4 -1 ... -
PAT1038 Recover the Smallest Number
2012-11-20 23:52 1668由一道面试题改的 把数组排成最小的数 不同之处是这 ... -
PAT1024 Palindromic Number
2012-11-20 23:51 648Sample Input 1: 67 3 Sampl ... -
PAT1015 Reversible Primes
2012-11-19 23:51 771十进制转任意进制 假设十进制数为number,转 ... -
PAT1012 The Best Rank
2012-11-19 23:50 927四门功课,输出排名最高的是哪个 Sample Inpu ... -
PAT1011 World Cup Betting
2012-11-19 23:50 534Sample Input 1.1 2.5 1.7 1.2 ...
相关推荐
这是动态规划中,求最长公共子序列(Longest common string)的源代码。自己编写执行。程序简单,有注释。
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Java AC 版本
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with...
LMS Longest Monotonically Increasing Sequence Algorithm
关于Longest Common Subsequences演算法
北大POJ2533-Longest Ordered Subsequence【O(nlogn)】
Longest Ordered Subsequence,算法分析与设计,C语言程序
Longest Common Ancestor classic ppt...
编写一个程序,对输入的字符串s和t,求其最长的公共子字符串。
Pku acm 第2533题 Longest Ordered Subsequence 代码,有详细的注释,动态规划
LCS(Longest common string)连续问题的求解,C++编写,稳定,高效.
approximate string searching ✩Lucian Ilie a,∗,1, Gonzalo Navarro b,2, Liviu Tinta a a Department of Computer Science, University of Western Ontario, N6A 5B7, London, Ontario, Canada b Department of ...
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. ...
LCS(longest common substring)算法,即最大公共子串,它是求两个字符串最长公共子串的问题。大体解法是用一个矩阵来记录两个字符串中所有位置的两个字符之间的匹配情况,若是匹配则为1,否则为0。然后求出对角线最长...
LeetCode Longest Common Prefix解决方案
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with...
北大POJ2533-Longest Ordered Subsequence 解题报告+AC代码
在音乐检索的实现中,提出一种有限长度的最长公共子序列(Local Longest Common String,LLCS)方法,该方法可有效解决传统方法存在的误检问题。开发实现了一个通过哼唱/歌唱进行歌曲检索的原型系统。对大量的歌曲...
Estimating the Longest Increasing Subsequence in Nearly Optimal Time_在近似最优时间内估计最长增长子序列.pdf
最长的线 获取字符串的最长行长度。 它还可以正确计算包含ansi转义码的行的长度。...必需的类型: string 选项 stripAnsiCodes 类型: boolean 默认值: true 获取字符串的实际长度。 执照 麻省理工学院:copyright: