报数

搜到了ccf的题目,便想着做一做

 

 在自己的电脑上运行的

//报数
#include <iostream>

using namespace std;

//define N 4;

int have7(int num){
    if(num%7==0){
        return 1;
    }
    while(num!=0){
        if(num%10==7) return 1;
        else num = num/10;
    }
    return 0;
}
int main()
{
    int n, num=1, count=1; //count是已经报出了的数的个数(不含和7相关的那几个)
    int cnt[4] = {0,0,0,0};
    cin >> n;
    while(count<=n){
        if(have7(num)==1){  //该数跳过,不计入count里
            cnt[(num-1)%4]++;
        }
        else
            count++;

        num++;
    }
    for(int i=0;i<4;i++){
        cout << cnt[i] << endl;
    }

    return 0;
}

 

posted @ 2020-04-17 16:12  清心lh  阅读(178)  评论(0)    收藏  举报