CCF認證 201912-1 《報數》

基礎題,直接見cpp代碼。

#include <cstdio>
int n;
int per[4]={0};
bool have7(int i)
{
    int t=i;
    while(t)
    {
        if( t%10 == 7 )
            return true;
        else
            t/=10;
    }
    return false;
}
int main() {
    scanf("%d",&n);

    int num=1; //當前的數字
    int j=0; //當前的人的序號
    int count=0; //當前數了count個數字
    while(true)
    {
        if( num%7==0 || have7(num) )
        {
            per[j]++;  //j被跳過了一次

            j++;      //跳到下一個人
            j %= 4;
            num++;
            continue;
        }

        j++;
        j %= 4;
        num++;
        
        count++; //報數的數量
        if( count == n)
            break;
    }
    for(num=0;num<4;num++)
        printf("%d\n",per[num]);
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章