问题描述:
有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。
虽然这些说法纯属无稽之谈,但有时还要迎合大众的需求。某抽奖活动的奖券号码是5位数(10000-99999),要求其中不要出现带“4”的号码,主办单位请你计算一下,如果任何两张奖券不重号,最多可发出奖券多少张。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
int fn1 () { //自己的沙雕思路 ;
int i = 10000;
int a,b,c,d,e;
int count = 0;
for (i=10000; i<=99999; i++) {
a = i/10000;
b = i%10000/1000;
c = i%10000%1000/100;
d = i%10000%1000%100/10;
e = i%10000%1000%100%10;
if (a!=4&&b!=4&&c!=4&&d!=4&&e!=4) {
//printf("%d %d %d %d %d\n",a,b,c,d,e) ;
count++ ;
}
}
return count;
}
int fn2 () { //copy来的代码
int count ;
int a,b,c,d,e ;
for (a=1; a<10; a++) {
for (b=0; b<10; b++) {
for (c=0; c<10; c++) {
for (d=0; d<10; d++) {
for (e=0; e<10; e++) {
if (a!=4&&b!=4&&c!=4&&d!=4&&e!=4) {
count++ ;
}
}
}
}
}
}
return count ;
}
int fn3() //我认为好的代码;
{
int i = 10000 ;
int temp ;
int t = 10 ;
int count ;
for (i=10000; i<99999; i++)
{
temp = i ;
while (temp>0)
{
t = temp%10 ;
if (t==4)
{
count++ ;
break ;
}
else temp/=10 ;
}
}
return (99999-10000+1-count) ;
}
int fn4()
{
return 8*9*9*9*9 ; //自己的数学排列组合思路 ;
}
int main() {
printf("奖券数目为(fn1执行结果):%d\n" ,fn1()) ;
printf("奖券数目为(fn2执行结果):%d\n" ,fn2()) ;
printf("奖券数目为(fn3执行结果):%d\n" ,fn3()) ;
printf("奖券数目为(fn4执行结果):%d\n" ,fn4()) ;
}