偶串:
bool compare(string s1, string s2)
{
return s1.compare(s2) == 0;
}
int solve(string s)
{
int size = s.size();
if ((size % 2) != 0) size -= 1;
else size -= 2;
while (size)
{
if (compare(s.substr(0, size / 2), s.substr(size / 2, size / 2))) break; //重点是这里折半比较
else size -= 2;
}
return size;
}
回文:
int solve(string s)
{
map<char, int> m;
int size = s.size();
int num = 0;
for (int i = 0;i < size;i++)
{
m[s[i]]++;
if (m[s[i]] == 2)
{
++num;
m[s[i]] = 0;
}
}
return size - num * 2;
}