201912-1 報數

有人找你發表於2020-10-28

201912-1 報數

程式碼:

#include <iostream>
#include <vector>


using namespace std;


bool jump(int num){
    if(num%7 == 0){
        return true;
    }
    while(num != 0){
        int temp = num;
        num = (int)num/10;
        int currnum = temp - num*10;
        if(currnum == 7){
            return true;
        }
    }
    return false;
}

int main()
{

    int n;
    while(scanf("%d",&n) != EOF){
        vector<int> count(4,0);
        int curr = 0;
        for(int i = 1; curr < n;i++){
            int p = (i-1)%4;
            if(jump(i)){
                count[p]++;
            }else{
                curr++;
            }
        }

        for(int i = 0; i < 4;i++){
            printf("%d\n",count[i]);
        }
    }

    return 0;
}

相關文章