Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void solve();
- int main()
- {
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("error.txt", "w", stderr);
- freopen("output.txt", "w", stdout);
- #endif
- int t=1;
- /*is Single Test case?*/cin>>t;
- while(t--)
- {
- solve();
- cout<<"\n";
- }
- cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
- return 0;
- }
- void solve()
- {
- string s;
- cin>>s;
- //int s[0] = 1, s[s.length()-1] = -1;
- int ans1= 0, ans2 = 0;
- if(s[0] == s.back()){
- cout<<"No";
- return;
- }
- for (int i = 0; i < s.length(); ++i)
- {
- if(s[i] == s[0]){
- ans1 += 1;
- ans2 += 1;
- }
- else if(s[i] == s.back()){
- ans1 -= 1;
- ans2 -= 1;
- }
- else{
- ans1 += 1;
- ans2 -= 1;
- }
- }
- if(ans1 == 0 or ans2 == 0)
- cout<<"Yes";
- else
- cout<<"No";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement