Files
2024-06-03 16:57:59 +02:00

32 lines
719 B
C++

// Palindrome Reorder
#include<bits/stdc++.h>
using namespace std;
int main() {
map<char, int> char_to_count;
string s; cin >> s;
for (auto c: s) char_to_count[c]++;
string forward;
char middle = ' ';
for (auto &[ch, c]: char_to_count) {
if (c & 1) {
if (middle != ' ') {
cout << "NO SOLUTION" << endl;
return 0;
}
middle = ch;
forward.append(string((c - 1) / 2, ch));
} else {
forward.append(string(c/2, ch));
}
}
cout << forward;
if (middle != ' ') cout << middle;
std::reverse(forward.begin(), forward.end());
cout << forward << endl;
return 0;
}