fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while(t--)
  8. {
  9. string s;
  10. cin >> s;
  11. vector<char> v;
  12. int n = s.length();
  13. for(int i=0;i<n;i++)
  14. {
  15. if(s[i]=='T')
  16. {
  17. v.push_back('T');
  18. s[i]='0';
  19. }
  20. }
  21. for(auto x : v)
  22. {
  23. cout << x;
  24. }
  25. for(int i=0;i<n;i++)
  26. {
  27. if(s[i]!='0')
  28. {
  29. cout << s[i] ;
  30. }
  31. }
  32. cout << endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 5312KB
stdin
5
FFT
ABFBANTTA
FFTNTT
FFTFFTFFTNNTNNT
AFFTBFFNTTFTTZ
stdout
TFF
TTABFBANA
TTTFFN
TTTTTFFFFFFNNNN
TTTTTAFFBFFNFZ