暴力回文串


#include "pch.h"
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
int isHuiwen(string s) {
	auto i = s.begin(), j = s.end()-1;
	bool ok = 0;
	stack 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 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<

 

你可能感兴趣的:(C++)