题目描述
解题思路
遍历1 - n中的每一个数字,对每一位判断是否满足条件,满足则加上该数字,不满足,继续循环。
实现代码
#include <iostream>
using namespace std;
const int N = 10010;
int res;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++)
{
int x = i;
while (x)
{
int t = x % 10;
x /= 10;
if (t == 2 || t == 0 || t == 9 || t == 1)
{
res += i;
break;
}
}
}
cout << res << endl;
return 0;
}