Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <iostream>
- #define ll long long int
- using namespace std;
- typedef unsigned long long ull;
- #define M_PI 3.14159265358979323846
- #pragma GCC optimize ("Ofast")
- #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
- #pragma GCC optimize("unroll-loops")
- #define nl "\n"
- #define sp " "
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);cout.tie(NULL);
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- string s;cin>>s;
- unordered_map<char,int> mp;
- for(char ch:s)
- {
- mp[ch]++;
- }
- int c=0;char ch='$';
- for(auto &x:mp)
- {
- if(x.second%2==0){continue;}
- else{c++;ch=x.first;}
- if(c>1){break;}
- }
- if(c>1){
- cout<<"NO SOLUTION"<<endl;return 0;
- }
- if(c==1)
- {
- string ans(mp[ch],ch);
- for(auto &x:mp)
- {
- if(x.first!=ch)
- {
- string k(x.second/2,x.first);
- ans=k+ans+k;
- }
- }
- cout<<ans<<endl;
- }
- else{
- string ans="";
- for(auto &x:mp)
- {
- string k(x.second/2,x.first);
- ans=k+ans+k;
- }
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment