fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(x) x.begin(), x.end()
  4.  
  5. typedef long long ll;
  6.  
  7.  
  8.  
  9. void solve() {
  10. string s ;
  11. cin >> s ;
  12. map < char , ll > m ;
  13. ll cnt = 0 ;
  14. char c1 ;
  15. for (int i = 0 ; i < 26 ; i++ ) {
  16. ll x = count (s.begin () , s.end () ,'A' + i ) ;
  17. if ( x & 1 == 1 ) {
  18. c1 = 'A' + i ;
  19. cnt ++ ;
  20. m['A' + i ] = x-1 ;
  21.  
  22. }
  23. else if (x > 0) m['A' + i ] = x ;
  24.  
  25. }
  26.  
  27. if (cnt > 1 ) cout <<"NO SOLUTION" << endl ;
  28. else {
  29. string s1 ;
  30. for (auto e : m ) {
  31. s1 += string ( e.second /2 , e.first ) ;
  32. }
  33. cout << s1 ;
  34. if ( cnt == 1 ) cout << c1 ;
  35.  
  36. std::reverse(s1.begin(), s1.end());
  37. cout << s1<< endl ;
  38. }
  39.  
  40.  
  41. }
  42.  
  43. int main() {
  44. ll t ;
  45. /*cin >> t ;
  46.   while (t-- ) {*/
  47. solve();
  48.  
  49.  
  50. // }
  51.  
  52.  
  53.  
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout