Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int T[28];
  4. int main(){
  5. ios::sync_with_stdio(0);
  6. int t,n,g;
  7. n=0;
  8. g=-1;
  9. string s;
  10. cin>>t;
  11. for(int r=0; r<t; r++){
  12. cin>>s;
  13. for(int i=0; i<s.size(); i++){
  14. T[s[i]-'A']++;
  15. }
  16. for(int i=0; i<26; i++){
  17. if(T[i]%2==1){
  18. n++;
  19. g=i;
  20. }
  21. }
  22. if(n>1) cout<<-1;
  23. else{
  24. for(int i=0; i<26; i++){
  25. if(T[i]%2==0 && T[i]!=0) for(int u=0; u<T[i]/2; u++) cout<<(char)(i+'A');
  26. }
  27. if(g!=-1) for(int u=0; u<T[g]; u++) cout<<(char)(g+'A');
  28. for(int i=25; i>=0; i--){
  29. if(T[i]%2==0 && T[i]!=0) for(int u=0; u<T[i]/2; u++) cout<<(char)(i+'A');
  30. }
  31. }
  32. n=0;
  33. g=-1;
  34. for(int i=0; i<26; i++) T[i]=0;
  35. cout<<"\n";
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement