2017-金马五校程序设计竞赛-E -Find Palindrome
来源:互联网 发布:itunes无法连接到网络 编辑:程序博客网 时间:2024/05/17 01:01
Description
Given a string S, which consists of lowercase characters, you need to find the longest palindromic sub-string.
A sub-string of a string S is another string S’ that occurs “in” S. For example, “abst” is a sub-string of “abaabsta”. A palindrome is a sequence of characters which reads the same backward as forward.
Input
There are several test cases.
Each test case consists of one line with a single string S (1 ≤ |S | ≤ 50).
Output
For each test case, output the length of the longest palindromic sub-string.
Sample Input
sasadasabxabxzhuyuan
Sample Output
713
题意:求字符串中最长的回文串中的长度,例如sasadasa
中asadasa 是最长的回文串,,
#include<bits/stdc++.h>using namespace std;string expand_palindrome(string s, int l, int r) { int n = s.length(); while(l >= 0 && r < n && s[l] == s[r]) { l--; r++; } return s.substr(l + 1, r - l - 1);}//函数解释详见下面链接string get_longest_palin(string s) { int i; int n = s.length(); string longest = s.substr(0, 1); string t; for(i = 0; i < n; i++) { t = expand_palindrome(s, i, i); if(t.length() > longest.length()) { longest = t; } t = expand_palindrome(s, i, i + 1); if(t.length() > longest.length()) { longest = t; } } return longest;}int main(){ string s; while(cin>>s) { cout<<get_longest_palin(s).size()<<endl; } return 0;}
http://blog.csdn.net/zzran/article/details/8517653
阅读全文
0 0
- 2017-金马五校程序设计竞赛-E -Find Palindrome
- 2017上海金马五校程序设计竞赛 E:Find Palindrome
- 2017年上海金马五校程序设计竞赛:Problem E : Find Palindrome
- 2017年上海金马五校程序设计竞赛:Problem E : Find Palindrome
- 2017年上海金马五校程序设计竞赛:Find Palindrome
- 2017 -金马五校程序设计竞赛-A
- 2017-金马五校程序设计竞赛-I
- 2017上海金马五校程序设计竞赛部分题解
- 2017上海金马五校程序设计竞赛 A :STEED Cards
- 2017上海金马五校程序设计竞赛 B:Sailing
- 2017上海金马五校程序设计竞赛 K:Treasure Map
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem E : A No-story Kingdom
- 上海金马五校程序设计竞赛 Problem B : Sailing
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem B : Coach
- 2017年上海金马五校程序设计竞赛(网上资格赛) Problem J : Raising Bacteria
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem B : Coach
- 2017年上海金马五校程序设计竞赛(网上资格赛) Problem J : Raising Bacteria
- 2017年上海金马五校程序设计竞赛(网上资格赛)Problem H : DHU Club Festival
- Fiddler-中会话列表中添加显示IP、相应时间功能
- HDU
- Java继承的概念与实现
- 使用gdb调试多进程及多线程程序
- 编译原理_pl0程序分析及注释
- 2017-金马五校程序设计竞赛-E -Find Palindrome
- LeetCode----537. Complex Number Multiplication
- Window系统原版下载
- MonkeyEye电影售票系统--用例建模
- PHP之cookie工作流程
- 设计模式(8)观察者模式-行为型
- C#实现listview Group收缩扩展的方法
- LintCode题解(1)--A+B问题
- 解决ubuntu14.04系统没有声音的问题