第六届蓝桥杯——奖券数目

【问题描述】
有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。
虽然这些说法纯属无稽之谈,但有时还要迎合大众的需求。

某抽奖活动的奖券号码是5位数(10000-99999),要求其中不要出现带“4”的号码,
主办单位请你计算一下,如果任何两张奖券不重号,最多可发出奖券多少张。

【答案提交】
请提交该数字(一个整数),不要写任何多余的内容或说明性文字。


题解:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

bool judge(int n)
{
	do 
	{
		int t = n % 10;
		if(t == 4) return false;
		n /= 10;
	}while(n != 0);
	
	return true;
}

int main()
{
	int ans = 0;
    for (int i = 10000; i <= 99999; i ++)
        if(judge(i)) ans ++;

    cout << ans << endl;
    
    return 0;
}

答案:52488

发布了63 篇原创文章 · 获赞 5 · 访问量 828

猜你喜欢

转载自blog.csdn.net/weixin_46239370/article/details/105269843
今日推荐