[Offer收割]编程练习赛54 register

Ended

Participants:154

Verdict:Accepted
Score:100 / 100
Submitted:2018-04-08 12:16:41

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
typedef  long long ll;
using namespace std;
const ll mod=998244353;
int t,n,m,a,b;
char s[500005];
int main()
{
    cin>>s+1;
    int len=strlen(s+1);
    for(int i=1;i<=(1+len)/2;i++){
        int j=len-i+1;
        if(s[i]!=s[j]){
            int r=j;
            for(int l=i+1;l<=r;l++,r--){
                if(s[l]!=s[r]){
                    while(s[j-1]==s[j])j--;
                    cout<<j<<endl;
                    return 0;   
                }
            }
            while(s[i]==s[i-1])i--;
            cout<<i<<endl;
            return 0;
        }
    }
    int ans=(len+1)/2;
    while(s[ans]==s[ans-1]) ans--;
    cout<<ans<<endl;
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX