试题编号: 201912-1
试题名称: 报数
时间限制: 1.0s
内存限制: 512.0MB
需要注意的细节:
#include <bits/stdc++.h>
using namespace std;
bool check7(int x)
{
if (x % 7 == 0)//检查是否为7的倍数
return true;
while (x)//检查是否含有7
{
if (x % 10 == 7)
return true;
x /= 10;
}
return false;
}
int main()
{
int n, cnta = 0, cntb = 0, cntc = 0, cntd = 0, cnt = 0;
cin >> n;
int i = 1;
while (cnt < n)
{
if (check7(i))//如果含有7或者是7的倍数,则跳过,判断谁跳过了这个数
{
if (i % 4 == 1)
cnta++;
else if (i % 4 == 2)
cntb++;
else if (i % 4 == 3)
cntc++;
else
cntd++;
i++;
continue;
}
i++;
cnt++;//记录没有跳过的数 的个数
}
cout << cnta << endl
<< cntb << endl
<< cntc << endl
<< cntd << endl;
return 0;
}