#include "pch.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <sstream>
using namespace std;
int isHuiwen(string s) {
auto i = s.begin(), j = s.end()-1;
bool ok = 0;
stack<char> istack;
for (; i <= j; ++i) {
istack.push(*i);
}
stringstream ss;
while (!istack.empty()) {
ss << istack.top();
istack.pop();
}
string sss = ss.str();
if (s.compare(sss) == 0)
return s.size();
return -1;
}
class Solution {
public:
string longestPalindrome(string s) {
vector<string> iset;
for(int i=1;i<=s.size();++i)
for (int j = 0; j + i <= s.size(); ++j) {
string s2(s, j, i);
iset.push_back(s2);
}
int max = 0;
sort(iset.begin(), iset.end());
string maxs;
for (auto ss : iset) {
int i = isHuiwen(ss);
if (i >= max) {
max = i;
maxs = ss;
}
}
return maxs;
}
};
int main()
{
Solution x;
cout<<x.longestPalindrome("babad");
}