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 }
时间: 2024-08-21 17:21:55

ABCDE的相关文章

Codeforces Round #261 (Div. 2)[ABCDE]

Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden 题意: 一个正方形,它的边平行于坐标轴,给出这个正方形的两个点,求出另外两个点. 分析: 推断下是否平行X轴或平行Y轴,各种if. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: A.cpp * Create Date: 2014-0

Codeforces Round #264 (Div. 2)[ABCDE]

Codeforces Round #264 (Div. 2)[ABCDE] ACM 题目地址: Codeforces Round #264 (Div. 2) 这场只出了两题TAT,C由于cin给fst了,D想到正解快敲完了却game over了... 掉rating掉的厉害QvQ... A - Caisa and Sugar[模拟] 题意: Caisa拿s美元去超市买sugar,有n种sugar,每种为xi美元yi美分,超市找钱时不会找美分,而是用sweet代替,当然能用美元找就尽量用美元找.他

形如abcde/fghij = n 的表达式(C语言求解)

•题目:输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a~j恰好为数字0~9的一个排列,2<=n<=79 输入:62 输出:79546/01283=62 94736/01528=62 1 #include <stdio.h> 2 3 int main() 4 { 5 int n,x,y,temp;//a[10]={0}; 6 int i,j,flag; 7 scanf("%d",&n); 8 for(x=12345;x

UVA 725 Division ( 找出 abcde / fghij = N的形式—— 暴力枚举 )

Division Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divide

通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。 比如字符串“abacacde”过滤结果为“abcde”。

这是华为2013的一个机试题,会好半天才想出来,用了三个for循环,可能有点繁琐,但只要慢慢看还是好理解的, 题目: 通过键盘输入一串小写字母(a~z)组成的字符串.请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉. 比如字符串"abacacde"过滤结果为"abcde". #include<stdio.h> #include<string.h> void main() { char a[]="aba

Codeforces Round #260 (Div. 2) ABCDE

A题逗比了,没有看到All ai are distinct. All bi are distinct. 其实很水的.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 #define mnx 100002 8 9 10 struct latop{ 11 int p, q; 12 bo

埃利斯(A.Ellis)ABCDE情绪管理理论

埃利斯(A.Ellis)ABCDE情绪管理理论A :Activating Events(诱发事件)B :Beliefs(个体对诱发事件的评价.解释.看法)C :Consequences(个体情绪和行为的结果)D :Disputing(指同不合理的信念辩论)E :Effects(指通过疏通产生积极的情绪和行为) 不是有A导致C,而是由B导致C! 原文地址:https://www.cnblogs.com/utank/p/12017306.html

如何用最简单的方法打印$str = “abcde”每个字母; 可以用substr()

<?php $str='abcdefg'; for($i=0;$i<strlen($str);$i++){ Echo substr($str,$i,1);//abcdefg echo $str[$i];//abcdefg }

喵哈哈村的魔法考试 Round #3 (Div.2) ABCDE

官方题解:http://www.cnblogs.com/qscqesze/p/6480284.html 哗啦啦村的刁难(1) 描述 哗啦啦村作为喵哈哈村的对头,于是他们准备给喵哈哈村一个好看. 哗啦啦村的头号长老--鱼先生,就提出了以下问题: 给你三个木棍,问你这三个木棍,是否能够组成一个非退化的三角形! 输入 第一行一个整数T,表示测试组数的个数.接下来T行,每行三个整数,a,b,c.表示哗啦啦村提供的三根木棍. 满足1<=T<=1001<=a,b,c<=5000 输出 如果可以