我的代码:
#include <iostream>
using namespace std;
int record[4]={0};//记录四个人分别的报数次数,初始化为0
bool judge(int x){
if( x % 7 == 0){//7的倍数
return true;
}
while( x != 0 ){
if(x % 10 == 7){//包含7
return true;
}
x /= 10;
}
return false;
}
int main(){
int n;
cin>>n;
int turn = 0,num = 1,cnt = 0;
//turn记录当前是谁报数 甲0 乙1 丙2 丁3
while(cnt!=n){//当目前的报数次数与要求的报数次数不等时,进入循环
if(judge(num)){
record[turn % 4]++;
}else{//如果没有跳过,则计数
cnt++;
}
num++;
turn++;
}
for(int i=0;i<4;i++){
cout<<record[i]<<endl;
}
return 0;
}