// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include <algorithm>
#include<iomanip>
#include<string>
using namespace std;
class Palindrome {
public:
int getLongestPalindrome(string A, int n) {
int max = 1;
for (int i = 0; i < n; i++)
{
int num = 1;
for (int left = i - 1, right = i + 1; left >= 0 && right < n; left--, right++)
{
if (A[left] == A[right])
{
num += 2;
}
else
{
break;
}
}
if (max < num)
{
max = num;
}
}
for (int i = 0; i < n; i++)
{
int num = 0;
for (int left = i, right = i + 1; left >= 0 && right < n; left--, right++)
{
if (A[left] == A[right])
{
num += 2;
}
else
{
break;
}
}
if (max < num)
{
max = num;
}
}
return max;
}
};
int main()
{
string A = "abc1234321ab";
string B = "baabccc";
Palindrome p;
cout<<p.getLongestPalindrome(A, 12)<<endl;
cout << p.getLongestPalindrome(B, 7) << endl;
return 0;
}