返回题解分享
讨论 / 题解分享/ 帖子详情

好数(编程题) - 题解

#include <bits/stdc++.h>

using namespace std;

int n;

int main() {
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int v = i;
        int u = 1;
        int f = 1;
        do {
            if (v % 2 != u)
                f = 0;
            if (u == 1)
                u = 0;
            else
                u = 1;
        } while (v /= 10);
        if (f)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}
0 回复 0 转发 1 喜欢 3 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!