题头:本内容所有题面都来自博客:https://blog.csdn.net/ryo_218/article/details/79704030在此感谢!

1,奖券数目

有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。
虽然这些说法纯属无稽之谈,但有时还要迎合大众的需求。某抽奖活动的奖券号码是5位数(10000-99999),要求其中不要出现带“4”的号码,主办单位请你计算一下,如果任何两张奖券不重号,最多可发出奖券多少张。

 

思路:5重循环,搞定。

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int ans = 0;
    for(int a = 1; a <= 9; ++a)
        for(int b = 0; b <= 9; ++b)
            for(int c = 0; c <= 9; ++c)
                for(int d = 0; d <= 9; ++d)
                    for(int e = 0; e <= 9; ++e)
                    {
                        if(a != 4 && b != 4 && c != 4 && d != 4 && e != 4)
                        {
                            ans++;
                        }
                    }
    printf("%d\n", ans);
}
View Code

相关文章: