1、奖券数目

题目 奖券数目

image-d25334c1

思路分析

直接循环 把每一个数拆解出每一位 发现有4就break 并标记为flase

如果某数标记为true 就cnt++

image-eaae9bae

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

int main()

{

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int cnt=0;

	for(int i=10000;i<=99999;i++){

		int x=i;

		bool havenot4=true;

		while(x){

			if(x%10==4){

				havenot4=false;

				break;

			}

			x/=10;

		}

		if(havenot4)

			cnt++;

	}

	cout<<cnt;

	return 0;

}

同类题型

视频讲解


⬅️ 第八届 c++ B组 省赛 🏠 00-刷题理模型 ➡️ 2、星系炸弹