Advertisement
Saleh127

cses 1755

Sep 25th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. string a;
  12. ll f[26]= {0},i,j=0,k=-1,l;
  13. cin>>a;
  14. for(i=0; i<a.size(); i++)
  15. {
  16. f[a[i]-'A']++;
  17. }
  18. for(i=0; i<26; i++)
  19. {
  20. if(f[i]%2)
  21. {
  22. j++;
  23. k=i;
  24. }
  25. }
  26. if(j>1) cout<<"NO SOLUTION"<<endl;
  27. else
  28. {
  29. string x="";
  30. for(i=0; i<26; i++)
  31. {
  32. if(k>-1 && k==i)
  33. {
  34. continue;
  35. }
  36. else
  37. {
  38. l=f[i]/2;
  39. for(j=0; j<l; j++)
  40. {
  41. x+=('A'+i);
  42. }
  43. }
  44. }
  45. cout<<x;
  46. if(k>-1)
  47. {
  48. l=f[k];
  49. char z=k+'A';
  50. for(j=0; j<l; j++)
  51. {
  52. cout<<z;
  53. }
  54. }
  55. reverse(x.begin(),x.end());
  56. cout<<x;
  57. cout<<endl;
  58. }
  59. return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement