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

特别数的和(编程题) - 题解

#include <bits/stdc++.h>
using namespace std;

bool check(int i) {
while (i) {
if (i % 10 <= 2 || i % 10 == 9)
return true;
i = i / 10;
}
return false;
}

int main() {
long long l, n, ans;
ans = 0;
cin >> n;
for (l = 1; l <= n; l++) {
if (check(l))
ans = ans + l;
}
cout << ans;
return 0;
}
0 回复 0 转发 0 喜欢 2 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!