试题编号: 201912-1
试题名称: 报数
时间限制: 1.0s
内存限制: 512.0MB


代码:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
// 明确一点,不算上没跳的,总共是n个数
bool judice(int number){
if(number % 7 == 0){
return true;
}else{
while(number > 0){
int a = number % 10;
if(a == 7){
return true;
}
number /= 10;
}
}
return false;
}
int main(){
int number[4];
int n;
while(cin >> n){
memset(number , 0 ,sizeof(number));
int count = 0;
int jishu = 1; //报的数
while(count < n){
if(judice(jishu)){
number[jishu % 4]++; //0代表了丁
}else{
count++;
}
jishu++;
}
for(int i = 1 ; i < 4; i++){
cout << number[i] << endl;
}
cout << number[0] << endl;
}
return 0;
}
本文深入探讨了一种基于报数游戏的算法实现,通过判断数字是否包含特定条件,如是否为7的倍数或含有数字7,来决定游戏流程。文章详细介绍了使用C++进行编程的全过程,包括核心函数judice的逻辑设计,以及主函数中如何通过循环和计数实现游戏规则。
367

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



