[蓝桥杯][2019年第十届真题]特别数的和

水题。

const int N=10010;
int n;

bool check(int x)
{
    bool ok=false;
    while(x)
    {
        int t=x%10;
        if(t == 2 || t == 0 || t == 1 || t == 9) ok=true;
        x/=10;
    }
    return ok;
}

int main()
{
    cin>>n;

    int res=0;
    for(int i=1;i<=n;i++)
        if(check(i))
            res+=i;
    cout<<res<<endl;
    //system("pause");
    return 0;
}
posted @ 2021-03-24 10:49  Dazzling!  阅读(26)  评论(0编辑  收藏  举报