CCF201912-1 报数

代码长度 1.161KB
编程语言 C0X
评测结果 正确
得分 100
时间使用 0ms
空间使用 672.0KB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
using namespace std;
int times[4] = {0, 0, 0, 0};

bool skip(int x) {
if (x % 7 == 0) return true;
while (x > 0) {
if (x % 10 == 7) return true;
x /= 10;
}
return false;
}

int main() {
assert(!skip(6)); assert(!skip(1));
assert(skip(7)); assert(skip(17)); assert(skip(71)); assert(skip(711)); assert(skip(117)); assert(skip(171));
ios_base::sync_with_stdio(false);
// n: 要喊的数的数量
// i: 要喊的数
// cnt:已喊的数
int n, i=1;
cin >> n;
for(int cnt=0; cnt<n; i++) {
int who = (i-1)%4;
if(skip(i)) {
times[who]++;
} else {
cnt++;
}
}
cout << times[0] << endl
<< times[1] << endl
<< times[2] << endl
<< times[3] << endl;
}
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

请我喝杯咖啡吧~

支付宝
微信