题解:CF2065B Skibidus and Ohio

· · 题解

正言

容易发现,如果这个字符串中有一个相邻且相同的字符,那么答案为 1,因为它可以变为自己左边或者右边的字符。

否则答案为 n

代码

#include<bits/stdc++.h>
using namespace std;
string s;
int n,T,r;
int main()
{
    cin>>T;
    while(T--){
        cin>>s;
        s=" "+s;
        r=-1;
        n=s.length();
        for(int i=n;i>=2;i--){
            if(s[i]==s[i-1]){
                r=i;
                break;
            }
        }
        if(r!=-1)cout<<1<<endl;
        else cout<<n-1<<endl;
    }
    return 0;
}