栗酱数数

链接:https://ac.nowcoder.com/acm/challenge/terminal
来源:牛客网

题目描述
栗酱在酒桌上玩一个小游戏,第一个人从1开始数数,如果遇到数字中含4或者数字是4的倍数则跳过报下一个,谁数错了就要罚酒一杯。

所以栗酱想让你写个程序把所有数生成出来,这样她就可以作弊直接读了。你一定能解决的吧?

输入描述:
只有一组数据,一个数n代表从1开始数到n。(n≤100000)
输出描述:
按顺序输出所有1到n之间任何一位都不是4的数,每两个数之间用一个回车隔开。
示例1
输入
复制
9
输出
复制
1
2
3
5
6
7
9

题目思路:

利用数组进行所有数据的判断,再输出

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		int b[100005];
		memset(b, 0, sizeof(b));
		for (int i = 1; i <= n; i++) {
			if (i % 4 == 0) {//把是4的倍数的=1
				b[i] = 1;
				continue;//continue防超时
			}
			int a = i;
			while (a != 0) {
				if (a % 10 == 4) {
					b[i] = 1;//把带4的=1
					break;//break防超时
				}
				a = a / 10;
			}
		}
		for (int i = 1; i <= n; i++) {
			if (b[i] == 0) {
				cout << i << endl;
			}
		}
	}
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值