1040. Longest Symmetric String

来源:互联网 发布:淘宝外包多少钱 编辑:程序博客网 时间:2024/04/30 02:46

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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <deque>
#include <queue>
#include <cstring>
#include <vector>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;
#define max1 10010
int main() {
string s;
getline(cin,s);
int maxlen=1;
string g="@#";
for(int i=0;i<s.size();i++)
{
g=g+s[i]+'#';
}
int n=g.size();
for(int i=1;i<n;i++)
{
int a=1,count=0;
while(g[i+a]==g[i-a])
{
count++;
a++;
}
maxlen=max(count,maxlen);
}
cout<<maxlen;
return 0;
}
0 0
原创粉丝点击