Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int T[28];
- int main(){
- ios::sync_with_stdio(0);
- int t,n,g;
- n=0;
- g=-1;
- string s;
- cin>>t;
- for(int r=0; r<t; r++){
- cin>>s;
- for(int i=0; i<s.size(); i++){
- T[s[i]-'A']++;
- }
- for(int i=0; i<26; i++){
- if(T[i]%2==1){
- n++;
- g=i;
- }
- }
- if(n>1) cout<<-1;
- else{
- for(int i=0; i<26; i++){
- if(T[i]%2==0 && T[i]!=0) for(int u=0; u<T[i]/2; u++) cout<<(char)(i+'A');
- }
- if(g!=-1) for(int u=0; u<T[g]; u++) cout<<(char)(g+'A');
- for(int i=25; i>=0; i--){
- if(T[i]%2==0 && T[i]!=0) for(int u=0; u<T[i]/2; u++) cout<<(char)(i+'A');
- }
- }
- n=0;
- g=-1;
- for(int i=0; i<26; i++) T[i]=0;
- cout<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement