fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve()
  5. {
  6. string str1;
  7. string str;
  8. cin>>str;
  9. if(str.length()%2==0 && str[0]!=str[1])
  10. {
  11. str1.push_back(str[0]);
  12. str1.push_back(str[1]);
  13. int j=0;
  14. bool flag=true;
  15. for(int i=0;i<str.length();i++)
  16.  
  17. {
  18. if(j==str1.length())
  19. { j=0;
  20. if(str[i]==str1[j])
  21. {
  22. j++;
  23. }
  24. else {
  25. flag=false;
  26. break;}
  27.  
  28. }
  29. else if(str[i]==str1[j])
  30. {
  31. j++;
  32. }
  33. else {
  34. flag=false;
  35. break;}
  36.  
  37. }
  38. if (flag==false)
  39. {
  40. cout<<"NO"<<"\n";
  41. }
  42. else
  43. cout<<"YES"<<"\n";
  44.  
  45. }
  46.  
  47. else
  48. cout<<"NO"<<"\n";
  49. }
  50. int main()
  51. {
  52. ios_base::sync_with_stdio(false);
  53. cin.tie(NULL);
  54. cout.tie(NULL);
  55.  
  56. int t;
  57. cin>>t;
  58. while(t--)
  59. {
  60. solve();
  61. }
  62.  
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5440KB
stdin
5
aabbabababab
cdcdcdcdcdcd
ababab
abababaabbaab
ABAC
stdout
NO
YES
YES
NO
NO