蓝桥杯 好数【暴力、基础知识】
题目:
AC代码:
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int n;
bool check(int x){
int cnt=1;
while(x!=0){
int t=x%10;
if(cnt%2==1){
if(t%2==0) return false; //奇数位置是偶数
}
if(cnt%2==0){
if(t%2==1) return false; //偶数位是奇数
}
cnt++;//升位
x=x/10; //升位
}
return true;
}
void solve(){
for(int i=1;i<=n;i++){
if(check(i)==true){
ans++;
}
}
cout<<ans<<endl;
return;
}
int main(){
cin>>n;
solve();
return 0;
}