CCF-CSP认证 201912-12报数
#include <bits/stdc++.h>
using namespace std;
int judge(int x){
if (x % 7 == 0) return 1;
while (x){
if (x % 10 == 7) return 1;
x /= 10;
}
return 0;
}
int main() {
int cnt = 1;//一共被真实报了几个数字
int num = 1;//当前的数字是多少
int Cnt[5] = {0};//甲乙丙丁被跳过的次数之和
int n;
scanf("%d", &n);
while (cnt <= n){
if (judge(num)) {
Cnt[(num-1) % 4 + 1]++;
}
else{
cnt++;
}
num++;
}
for (int i = 1; i <= 4; i++){
printf("%d\n", Cnt[i]);
}
return 0;
}
本文深入探讨了CCF-CSP认证中的一道报数题,通过C++实现了一个算法来解决该问题。算法核心在于判断数字是否包含7或能被7整除,以此决定是否跳过该数字,并统计四位玩家各自被跳过的次数。
723

被折叠的 条评论
为什么被折叠?



