diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
| commit | 96254947699986c59f0dc63d69fd4b76bd3ed43e (patch) | |
| tree | 6c4dca945d7f7427c48be234d827fe4d33be02c5 /01_introductory_problems/palindrome_reorder_1755.cpp | |
| download | cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip | |
Initial commit
Diffstat (limited to '')
| -rw-r--r-- | 01_introductory_problems/palindrome_reorder_1755.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/01_introductory_problems/palindrome_reorder_1755.cpp b/01_introductory_problems/palindrome_reorder_1755.cpp new file mode 100644 index 0000000..8ebf4f4 --- /dev/null +++ b/01_introductory_problems/palindrome_reorder_1755.cpp | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <string> | ||
| 3 | |||
| 4 | void printn(char c, int n) { | ||
| 5 | for (int i = 0; i < n; i++) | ||
| 6 | std::cout << c; | ||
| 7 | } | ||
| 8 | |||
| 9 | int main() { | ||
| 10 | std::string s; | ||
| 11 | int odd{0}, a['Z'+1] = {0}; | ||
| 12 | char oddc{0}; | ||
| 13 | std::cin >> s; | ||
| 14 | for (auto c : s) | ||
| 15 | a[(size_t)c]++; | ||
| 16 | for (char c = 'A'; c <= 'Z'; c++) { | ||
| 17 | if (a[(size_t)c] % 2) { | ||
| 18 | odd++; | ||
| 19 | oddc = c; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | if (odd > 1) { | ||
| 23 | std::cout << "NO SOLUTION\n"; | ||
| 24 | } else { | ||
| 25 | for (char c = 'A'; c <= 'Z'; c++) | ||
| 26 | if (c != oddc) | ||
| 27 | printn(c, a[(size_t)c]/2); | ||
| 28 | if (odd) | ||
| 29 | printn(oddc, a[(size_t)oddc]); | ||
| 30 | for (char c = 'Z'; c >= 'A'; c--) | ||
| 31 | if (c != oddc) | ||
| 32 | printn(c, a[(size_t)c]/2); | ||
| 33 | std::cout << std::endl; | ||
| 34 | } | ||
| 35 | } | ||
