求1000-9999之间的吸血鬼数字(穷举法Java实现)

当初学Java时做的。

代码:

展开
 1 public class XiXueGuiNum {
 2  
 3      /**
 4       * @param args
 5       */
 6      public static void main(String[] args) {
 7          // TODO Auto-generated method stub
 8          int num[] = new int[4];
 9          for(int i = 1000;i < 10000;++i){
10              if(i%100 == 0)
11                  continue;
12              convertToSingleValue(i,num);
13              
14              for(int a = 0; a < num.length;++a)
15              {
16                  for(int b = 0;b < num.length;++b)
17                  {
18                      if(a == b)
19                          continue;
20                      for(int c = 0;c < num.length;++c)
21                      {
22                          if(c == a || c == b)
23                              continue;
24                          for(int d = 0;d < num.length;++d)
25                          {
26                              if(d == a || d == b || d == c)
27                                  continue;
28                              if((num[a]*10 + num[b]) * (num[c]*10 + num[d]) == i)
29                                  System.out.println(i + "=" + (num[a]*10 + num[b]) + "*" + (num[c]*10 + num[d]));
30                          }
31                      }
32                  }
33              }
34              
35              if((num[0] * 10 + num[1]) * (num[2] * 10 + num[3]) == i)
36              {
37                  System.out.println(i+"=" + num[0]*10 + num[1] + "*" + num[2]*10 + num[3]);
38              }
39          }
40      }
41      public static void convertToSingleValue(int value,int[] num)
42      {
43          int temp = value;
44          int quotient = 0;
45          int remainder = 0;
46          int[] times = {1000,100,10,1};
47          for(int i = 0;i < num.length;++i)
48          {
49              quotient = temp/times[i];
50              remainder = temp % times[i];
51              temp = remainder;
52              num[i] = quotient;
53          }
54      }
55  }

 

 

转载于:https://www.cnblogs.com/jinks/archive/2013/04/26/3045755.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值