This commit is contained in:
2024-06-01 23:50:25 +02:00
parent ca126c7a0a
commit 5f6b389ee3
8 changed files with 188 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
// 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;
}