题目描述
好数,打卡题,奇数位为奇数,偶数位为偶数,统计1~n共有几个好数
#include <iostream>
#include <cstring>
#include <algorithm>
#include<bits/stdc++.h>
#define int long long
using namespace std;
bool check(int x)
{
int cnt = 1;
while (x)
{
int r = x % 10;
if (r % 2 != cnt % 2) return false;
x /= 10, cnt ++ ; //cnt用于判断奇偶性位 x/10表示去掉最后一位
}
return true;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int res = 0;
for (int i = 1; i <= n; i ++ )
if (check(i))
res ++ ;
cout << res << endl;
return 0;
}