CSP認證 201912-1 報數(模擬)

會做飯的好先生發表於2020-11-30

解題思路:

演算法標籤:模擬

程式碼:

// TSWorld
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 50;
bool iscount(int number) {
	if(number % 7 == 0)
		return false;
	int temp = 0;
	while(number != 0) {
		temp = number%10;
		if(temp == 7)
			return false;
		number /= 10;
	}
	return true;
}

int people[10];

int main()
{
	int times = 1;
	int ans = 0;
	int n = 0;
	cin>>n;

	while(ans < n) {
		for(int i = 1;i <= 4;i++) {
			if(ans >= n)
				break;
			if(!iscount(times)){
				people[i]++;
				times++;
				continue;
			}
			else {
				times++;
				ans++;
				continue;
			}

		}
	}

	for(int i = 1;i < 4;i++)
		cout<<people[i]<<endl;
	cout<<people[4];
	return 0;
}

相關文章