蓝桥杯-好数

#include <iostream>
using namespace std;
const int N=1e7+10;
int a[N];
int n;
bool isGoodNum(int x)
{
	int count=0;
	while(x>0)
	{
		a[++count]=x%10;
		x=x/10;
	}
	
	for(int i=1;i<=count;i++)
	{
		 if((i%2!=0)&&(a[i]%2==0)) return false;
		 
		 if((i%2==0)&&(a[i]%2!=0)) return false;
	}
	
	return true;
}
int main()
{
    cin>>n;
    
    int count=0;
    for(int i=1;i<=n;i++)
    {
    	if(isGoodNum(i)){
    		count++;
		} 
	}
    
   cout<<count<<endl;


  return 0;
}
posted @ 2024-10-21 20:37  Emila  阅读(15)  评论(0)    收藏  举报