题目思路
题意在题目描述中已经表达得很清楚了,如果注意读题,不遗漏信息,这应该是一道妥妥的水题。
设变量 表示报出了多少个数字(不计入被跳过的数),变量 表示包含跳过的数,当前报到多少,数组 记录四个人被跳过的次数,函数 检查 是否为包含7或者为7的倍数的数。
我们只要去模拟这个报数的过程,不断递增 的值,同时用 函数检查是否需要跳过,如果不需要跳过就增加 的值,否则增加被跳过的次数。直到 的值等于 。
我们发现, 的数是轮到甲报的, 的数是轮到乙报的……,于是我们就可以在他们被跳过时,用 进行计数。
代码如下
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e3 + 10;
int n, a[10];
/**
* 检查n是否为包含7或者为7的倍数的数
* 如果是就返回0,否则返回1
*/
int check(int n) {
if (n % 7 == 0) return 0;
while (n) {
if (n % 10 == 7) return 0;
n /= 10;
}
return 1;
}
int main()
{
scanf("%d", &n);
int cnt = 0, num = 0;
while (1) {
num++;
if (check(num)) {
cnt++;
} else {
a[(num - 1) % 4]++;
}
if (cnt == n) break;
}
for (int i = 0; i < 4; i++)
printf("%d\n", a[i]);
return 0;
}