【CCF历年题题解】201912-1 报数

模拟,注意跳过的数不计入

#include <iostream>

using namespace std;

int p[4];

bool check(int x)
{
    
    
    while(x > 0)
    {
    
    
        int t = x % 10;
        if(t == 7) return true;
        x /= 10;
    }
    
    return false;
}

int main()
{
    
    
    int n;
    cin >> n;
    
    int cnt= 1;
    int i = 0;

    while(cnt <= n )
    {
    
    
        i ++ ;
        if((i >= 7 && i % 7 ==0) || check(i))
        {
    
    
            p[i%4] ++;
            continue;
        }
        
        cnt ++;
    }
    
    for(int i=1;i<4;i++) cout<<p[i]<<endl;
    cout<<p[0];
    
   
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43154149/article/details/107955206