老师出了一道题,只能写到这样,总是有错误,求大神指导
A、B、C、D、E、F、G、H、I、J 共10名学生有可能参加本次计算机竞赛,也可能不参加。因为某种原因,他们是否参赛受到下列条件的约束:1. 如果A参加,B也参加;
2. 如果C不参加,D也不参加;
3. A和C中只能有一个人参加;
4. B和D中有且仅有一个人参加;
5. D、E、F、G、H 中至少有2人参加;
6. C和G或者都参加,或者都不参加;
7. C、E、G、I中至多只能2人参加
8. 如果E参加,那么F和G也都参加。
9. 如果F参加,G、H就不能参加
10. 如果I、J都不参加,H必须参加
请编程根据这些条件判断这10名同学中参赛者名单。如果有多种可能,则输出所有的可能情况。
public class Test{
public static void main (String[] args){
int[] constvalue = {1,2,4,8,16,32,64,128,256,512};
for(int i=0;i<1024;i++){
if(((i&constvalue['a'-'a'])==constvalue['a'-'a'])
&&((i&constvalue['b'-'a'])==0)){
continue;}
if(!((i&constvalue['c'-'a'])==constvalue['c'-'a'])
&&((i&constvalue['d'-'a'])==constvalue['d'-'a'])){
continue;}
if(((i&constvalue['a'-'a'])==constvalue['a'-'a'])
&&((i&constvalue['c'-'a'])==constvalue['c'-'a'])){
continue;}
if((((i&constvalue['b'-'a'])==constvalue['b'-'a'])&&((i&constvalue['d'-'a'])==constvalue['d'-'a']))
||(!(i&constvalue['b'-'a']==constvalue['b'-'a'])&&!((i&constvalue['d'-'a'])==constvalue['d'-'a']))){
continue;}
if((((i&constvalue['d'-'a'])==constvalue['d'-'a'])+((i&constvalue['e'-'a'])==constvalue['e'-'a'])+
((i&constvalue['f'-'a'])==constvalue['f'-'a'])+((i&constvalue['g'-'a'])==constvalue['g'-'a'])+
((i&constvalue['h'-'a'])==constvalue['h'-'a']))<2){
continue;}
if((!((i&constvalue['c'-'a'])==constvalue['c'-'a'])&&((i&constvalue['g'-'a'])==constvalue['g'-'a']))
||(((i&constvalue['c'-'a'])==constvalue['c'-'a'])&&(!((i&constvalue['g'-'a'])==constvalue['g'-'a'])))){
continue;}
if((((i&constvalue['c'-'a'])==constvalue['c'-'a'])+((i&constvalue['e'-'a'])==constvalue['e'-'a'])+
((i&constvalue['g'-'a'])==constvalue['g'-'a'])+((i&constvalue['i'-'a'])==constvalue['i'-'a']))>2){
continue;}
if((((i&constvalue['e'-'a'])==constvalue['e'-'a'])&&(!((i&constvalue['f'-'a'])==constvalue['f'-'a'])))
||(((i&constvalue['e'-'a'])==constvalue['e'-'a'])&&(!((i&constvalue['g'-'a'])==constvalue['g'-'a'])))){
continue;}
if((((i&constvalue['f'-'a'])==constvalue['f'-'a'])&&((i&constvalue['g'-'a'])==constvalue['g'-'a']))
||(((i&constvalue['f'-'a'])==constvalue['f'-'a'])&&((i&constvalue['h'-'a'])==constvalue['h'-'a']))){
continue;}
if(((!((i&constvalue['i'-'a'])==constvalue['i'-'a']))&&(!((i&constvalue['j'-'a'])==constvalue['j'-'a']))
&&(!((i&constvalue['h'-'a'])==constvalue['h'-'a'])))){
continue;}
if((i&constvalue['a'-'a'])==constvalue['a'-'a']){
System.out.print("A");}
if((i&constvalue['b'-'a'])==constvalue['b'-'a']){
System.out.print("B");}
if((i&constvalue['c'-'a'])==constvalue['c'-'a']){
System.out.print("C");}
if((i&constvalue['d'-'a'])==constvalue['d'-'a']){
System.out.print("D");}
if((i&constvalue['e'-'a'])==constvalue['e'-'a']){
System.out.print("E");}
if((i&constvalue['f'-'a'])==constvalue['f'-'a']){
System.out.print("F");}
if((i&constvalue['g'-'a'])==constvalue['g'-'a']){
System.out.print("G");
if((i&constvalue['h'-'a'])==constvalue['h'-'a']){
System.out.print("H");}
if((i&constvalue['i'-'a'])==constvalue['i'-'a']){
System.out.print("I");}
if((i&constvalue['j'-'a'])==constvalue['j'-'a']){
System.out.print("J");}
System.out.println();
}
}
}
}