beephsupreme

alternative palindrome

Aug 24th, 2022 (edited)
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3. #define ll long long int
  4. using namespace std;
  5. typedef unsigned long long ull;
  6. #define M_PI 3.14159265358979323846
  7. #pragma GCC optimize ("Ofast")
  8. #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  9. #pragma GCC optimize("unroll-loops")
  10. #define nl "\n"
  11. #define sp " "
  12.  
  13.  
  14. int main()
  15. {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(NULL);cout.tie(NULL);
  18.  
  19. // freopen("input.txt","r",stdin);
  20. // freopen("output.txt","w",stdout);
  21.  
  22. string s;cin>>s;
  23. unordered_map<char,int> mp;
  24.  
  25. for(char ch:s)
  26. {
  27. mp[ch]++;
  28. }
  29. int c=0;char ch='$';
  30. for(auto &x:mp)
  31. {
  32. if(x.second%2==0){continue;}
  33. else{c++;ch=x.first;}
  34. if(c>1){break;}
  35. }
  36. if(c>1){
  37. cout<<"NO SOLUTION"<<endl;return 0;
  38. }
  39.  
  40.  
  41. if(c==1)
  42. {
  43. string ans(mp[ch],ch);
  44. for(auto &x:mp)
  45. {
  46. if(x.first!=ch)
  47. {
  48. string k(x.second/2,x.first);
  49. ans=k+ans+k;
  50. }
  51. }
  52. cout<<ans<<endl;
  53. }
  54. else{
  55. string ans="";
  56. for(auto &x:mp)
  57. {
  58. string k(x.second/2,x.first);
  59. ans=k+ans+k;
  60. }
  61. cout<<ans<<endl;
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment