Test 2

问题描述:
有些人很迷信数字,比如带“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()) ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值