CSP 201912-1报数

CSP 201912-1 报数

思路: 水题,模拟即可
代码:

#include
using namespace std;

bool fun(int x)
{
    if(x%7==0)
    {
        return true;
    }
    int t=0;
    while(x)
    {
        t=x%10;
        if(t==7)
        {
            return true;
        }
        x/=10;
    }
    return false;
}
int main()
{
    int n;
    cin>>n;
    int s[5];
    memset(s,0,sizeof(s));
    int cnt=1;
    int i=1;
    int j=1;
    while(cnt<=n)
    {
    	if(fun(j))
        {
            s[i]++;
        }
        else
        {
            cnt++;
        }
        j++;
        i++;
        if(i==5)
            i=1;
    }
    for(i=1;i<=4;i++)
    {
        cout<<s[i]<<"\n";
	}	
    return 0;
}

你可能感兴趣的:(CSP 201912-1报数)