fork download
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int main(){
  5. int testCase=0;
  6. cin>>testCase;
  7. while(testCase>0){
  8.  
  9. int i=0,m=0;
  10. string str;
  11. cin.clear();
  12. cin.sync();
  13. getline(cin, str);
  14. string str1;
  15. string str2;
  16. if((str.size()%2)==0){
  17. m=str.size()/2;
  18. str1.resize(m);
  19. str2.resize(m);
  20. for(i=0;i<m;i++){
  21. str1[i] = str[i];
  22. }
  23. for(i=m;i<str.size();i++){
  24. str2[i-m] = str[i];
  25. }
  26. }
  27. else{
  28. m=floor(str.size()/2);
  29. str1.resize(m);
  30. str2.resize(m);
  31. for(i=0;i<m;i++){
  32. str1[i] = str[i];
  33. }
  34. for(i=m+1;i<str.size();i++){
  35. str2[i-m-1] = str[i];
  36. }
  37. }
  38. sort(str1.begin(), str1.end());
  39. sort(str2.begin(), str2.end());
  40. if(str1==str2){
  41. cout<<"YES " << str1 << "|" << str2 <<endl;
  42. }
  43. else{
  44. cout<<"NO " << str1 << "|" << str2 <<endl;
  45. }
  46.  
  47. testCase--;
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0s 4252KB
stdin
10
gaga
abcde
rotor
xyzxy
abbaab
ababc
aa
aa
aa
aa
aa
aa
stdout
YES |
YES ag|ag
NO ab|de
YES or|or
YES xy|xy
NO abb|aab
NO ab|bc
YES a|a
YES a|a
YES a|a