CCF---201912-1---报数---C++

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

问题描述:

在这里插入图片描述
在这里插入图片描述

实现代码

#include<iostream>
#include<cstring>
using namespace std;

int cnt[4];

bool Judge(int num){
	if(num % 7 == 0) return true;
	while(num != 0){
		int t = num % 10;
		if(t == 7) return true;
		num /= 10;
	}
	return false;
}

int main(){
	int n, flag = 0, sum = 0;
	memset(cnt, 0, sizeof(cnt));
	cin >> n;
	while(sum != n){
		if(Judge(++flag)){
			cnt[(flag-1) % 4]++;
		}
		else sum++;
	}
	for(int i= 0;i < 4; i++){
		cout << cnt[i] << endl;
	}
	return 0;
}
发布了145 篇原创文章 · 获赞 22 · 访问量 9653

猜你喜欢

转载自blog.csdn.net/weixin_44778155/article/details/103986996