Advertisement
Guest User

Untitled

a guest
Mar 8th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void solve();
  4. int main()
  5. {
  6. ios_base::sync_with_stdio(false);cin.tie(NULL);
  7.  
  8. #ifndef ONLINE_JUDGE
  9. freopen("input.txt", "r", stdin);
  10. freopen("error.txt", "w", stderr);
  11. freopen("output.txt", "w", stdout);
  12. #endif
  13.  
  14. int t=1;
  15. /*is Single Test case?*/cin>>t;
  16. while(t--)
  17. {
  18. solve();
  19. cout<<"\n";
  20. }
  21.  
  22. cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
  23. return 0;
  24. }
  25. void solve()
  26. {
  27. string s;
  28. cin>>s;
  29. //int s[0] = 1, s[s.length()-1] = -1;
  30. int ans1= 0, ans2 = 0;
  31. if(s[0] == s.back()){
  32. cout<<"No";
  33. return;
  34. }
  35. for (int i = 0; i < s.length(); ++i)
  36. {
  37. if(s[i] == s[0]){
  38. ans1 += 1;
  39. ans2 += 1;
  40. }
  41. else if(s[i] == s.back()){
  42. ans1 -= 1;
  43. ans2 -= 1;
  44. }
  45. else{
  46. ans1 += 1;
  47. ans2 -= 1;
  48. }
  49. }
  50. if(ans1 == 0 or ans2 == 0)
  51. cout<<"Yes";
  52. else
  53. cout<<"No";
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement