ABCDE

 1 package interview;
 2 
 3 import java.util.LinkedList;
 4 import java.util.List;
 5 
 6 public class ABCDE {
 7 
 8     private boolean ab(boolean a, boolean b){
 9         if(a && !b) return false;
10         return true;
11     }
12     
13     private boolean bc(boolean b, boolean c){
14         if(b && c) return false;
15         if(!b && !c) return false;
16         return true;
17     }
18     
19     private boolean cd(boolean c, boolean d){
20         if(c && !d) return false;
21         if(!c && d) return false;
22         return true;
23     }
24     
25     private boolean de(boolean d, boolean e){
26         if(!d && !e) return false;
27         return true;
28     }
29     
30     private boolean ead(boolean e, boolean a, boolean d){
31         if(e){
32             if(!a) return false;
33             if(!d) return false;
34         }
35         return true;
36     }
37     
38     public boolean trueCondition(boolean a, boolean b, boolean c, boolean d, boolean e){
39         if(ab(a, b) && bc(b, c) && cd(c, d) && de(d, e) && ead(e, a, d)) return true;
40         return false;
41     }
42     
43     public boolean trueCondition(List<Boolean> booleans){
44         boolean a, b, c, d, e;
45         a = booleans.get(0);
46         b = booleans.get(1);
47         c = booleans.get(2);
48         d = booleans.get(3);
49         e = booleans.get(4);
50         return trueCondition(a, b, c, d, e);
51     }
52     
53     public static List<Boolean> intToBooleanBit(int aInt, int size) {
54         if (aInt < 0) throw new IllegalArgumentException();
55         String bitString = "00000" + Integer.toBinaryString(aInt);
56         bitString = bitString.substring(bitString.length() - size);
57         List<Boolean> booleanList = new LinkedList<Boolean>();
58         for (int i = 0; i < bitString.length(); i++) {
59             booleanList.add(new Boolean(bitString.charAt(i) == '0' ? false : true));
60         }
61         return booleanList;
62     }
63     
64     public static void main(String[] args){
65         ABCDE instance = new ABCDE();
66         int pass = 32;
67         int size = 5;
68         for(int i=0; i<pass; i++){
69             List<Boolean> booleanList = intToBooleanBit(i, 5);
70             if(booleanList.size() != 5){
71                 System.out.println("bit list size error!");
72                 System.exit(-1);
73             }else{
74                 if(instance.trueCondition(booleanList)){
75                     System.out.println(booleanList.toString());
76                 }
77             }
78         }
79     }
80 }

 

转载于:https://www.cnblogs.com/dadad/p/ABCDE.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值