试题编号: | 201912-1 |
试题名称: | 报数 |
时间限制: | 1.0s |
内存限制: | 512.0MB |
问题描述: |
#include<iostream>
int tg[4]; //记录甲(tg[1])、已(tg[2])、丙(tg[3])、丁(tg[4])四人跳过的次数。
using namespace std;
//判断是否满足跳过的函数isContainSeven()
bool isContainSeven(int x) {
while(x){
int r = x%10;
if(r==7) {
return true;
break;
}
x = x/10;
}
return false;
}
int main(){
int n;
scanf("%d",&n); //输入总共报出的数n(不计入跳过的数)
int count = 0;//记载报出的个数(不计入跳过的数)
int i=1; //从1开始报数
while(true) {
if(i%7==0 || isContainSeven(i))
{
tg[i%4]++;
// cout<<"报数"<<i<<endl;
}
else count++;
if(count ==n) break;
i++;
}
//输出各自对应的跳过次数
//分别是甲:tg[1]、已:tg[2]、丙:tg[3]、丁:tg[0]
cout<<tg[1]<<endl;
cout<<tg[2]<<endl;
cout<<tg[3]<<endl;
cout<<tg[0]<<endl;
return 0;
}