若这一位和最后一位的奇偶性相同则合法,然后枚举每个位置即可。
#include<bits/stdc++.h> #define int long long #define double long double #define x first #define y second using namespace std; typedef long long LL; typedef long long ll; typedef pair<int,int> PII; const int N=3e5+10; const int M=1e3+10; int mod=1e9+7; int a[N]; // int cal(string s){ // int ans=0; // for(auto it:s) ans=ans*10+it-'0'; // return ans; // } void solve(){ string s;cin>>s; int ans=0; for(int i=0;i+1<s.size();i++){ int x=s[i]-'0',y=s[s.size()-1]-'0'; if((x+y)%2==0) ans++; } cout<<ans<<"\n"; } signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int _; _=1; //cin>>_; while(_--){ solve(); } }