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

Ended

Participants:154

Verdict:Accepted
Score:100 / 100
Submitted:2018-04-08 13:33:45

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
#include<bits/stdc++.h>
using namespace std;
char str[500005];
int find(int n){
    for(int i=2;i<=n;i++){
        if(str[i]!=str[i-1])return 1;
    }
    return 0;
}
int main(){
    int i,j,k;
    cin>>str+1;
    int n=strlen(str+1);
    for(i=1,j=n;i<j;j--,i++){
        if(str[i]!=str[j]){
            break;  
        }
    }
    if(str[i]==str[j-1]&&i!=j-1&&find(n)&&str[i+1]!=str[j]){
        cout<<j<<endl;
    }else{
        for(k=i;k>=0;k--){
            if(str[i]!=str[k]){
                break;
            }
        }
        cout<<k+1<<endl;
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX