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

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

#include <iostream>
#include <cstring>

using namespace std;

bool check(int x)
{
	while(x>0)
	{
		if(x%10<=2||x%10==9)//判断最后一位数是否含有0、1、2、9四个数字
{
		return true;
	}
		x/=10;
		//去除这一位数,循环继续判断左边一位是否符合要求 
	}
	return false; 
}



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