#include <iostream>
#include <algorithm>
#include "string"
#include "vector"
using namespace std;
int expandCenter(const string &s, int lo, int hi)
{
while (lo >= 0 && hi < s.size() && s[lo] == s[hi])
{
--lo;
++hi;
}
return hi - lo - 1;
}
string longestPalindrome(string s)
{
int begin = 0;
int end = 0;
for (int i = 0; i < s.size(); ++i)
{
int length = max(expandCenter(s, i, i), expandCenter(s, i, i + 1));
if (length > end - begin)
{
begin = i - (length - 1) / 2;
end = i + length / 2;
}
}
return s.substr(begin, end - begin + 1);
}
int main()
{
cout<<longestPalindrome("ac");
system("pause");
return 0;
}