爪哇国新游记之二十一----快算24

简介:

四张牌,通过四则运算得到24,一个数限用一次,快者为胜。

代码:

复制代码
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 快算24
 * @author heyang
 *
 */
public class Caculator{
    private double anticipate;// 预期结果
    private double op1;// 操作数一
    private double op2;// 操作数二
    private List<String> fomulaList;// 两个操作数进行四则运算能得到预期结果的算式列表
    
    // 仅算24的构造函数
    public Caculator(double[] arr){
        this(24,arr);
    }
    
    // 完全构造函数,可以指定结果
    public Caculator(double anticipate,double[] arr){
        // 2
        if(arr.length==2){
            this.anticipate=anticipate;
            op1=arr[0];
            op2=arr[1];
            fomulaList=getFomulaList();
        }
        
        if(arr.length==3){
            this.anticipate=anticipate;// C
            
            double[] arrNew;// A
            double anticipateNew;// arr[2]=B
            List<String> list;
            Caculator c;
            fomulaList=new ArrayList<String>();
            
            /// 0,1,2
            // A+B=C 
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            anticipateNew=anticipate-arr[2];
            c=new Caculator(anticipateNew,arrNew);
            
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")+"+arr[2]);
                }
            }
            
            // A-B=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            anticipateNew=anticipate+arr[2];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")-"+arr[2]);
                }
            }
            
            // B-A=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            anticipateNew=arr[2]-anticipate;
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[2]+"-("+str+")");
                }
            }
            
            // A*B=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            anticipateNew=anticipate/arr[2];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")*"+arr[2]);
                }
            }
            
            // A/B=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            anticipateNew=anticipate*arr[2];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")/"+arr[2]);
                }
            }
            
            // B/A=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            anticipateNew=arr[2]/anticipate;
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[2]+"/("+str+")");
                }
            }
            
            /// 1,2,0
            // A+B=C 
            arrNew=new double[2];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            anticipateNew=anticipate-arr[0];
            c=new Caculator(anticipateNew,arrNew);
            
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")+"+arr[0]);
                }
            }
            
            // A-B=C
            arrNew=new double[2];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            anticipateNew=anticipate+arr[0];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")-"+arr[0]);
                }
            }
            
            // B-A=C
            arrNew=new double[2];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            anticipateNew=arr[0]-anticipate;
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[0]+"-("+str+")");
                }
            }
            
            // A*B=C
            arrNew=new double[2];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            anticipateNew=anticipate/arr[0];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")*"+arr[0]);
                }
            }
            
            // A/B=C
            arrNew=new double[2];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            anticipateNew=anticipate*arr[0];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")/"+arr[0]);
                }
            }
            
            // B/A=C
            arrNew=new double[2];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            anticipateNew=arr[0]/anticipate;
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[0]+"/("+str+")");
                }
            }
            
            /// 0,2,1
            // A+B=C 
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[2];
            anticipateNew=anticipate-arr[1];
            c=new Caculator(anticipateNew,arrNew);
            
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")+"+arr[1]);
                }
            }
            
            // A-B=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[2];
            anticipateNew=anticipate+arr[1];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")-"+arr[1]);
                }
            }
            
            // B-A=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[2];
            anticipateNew=arr[1]-anticipate;
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[1]+"-("+str+")");
                }
            }
            
            // A*B=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[2];
            anticipateNew=anticipate/arr[1];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")*"+arr[1]);
                }
            }
            
            // A/B=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[2];
            anticipateNew=anticipate*arr[1];
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")/"+arr[1]);
                }
            }
            
            // B/A=C
            arrNew=new double[2];
            arrNew[0]=arr[0];
            arrNew[1]=arr[2];
            anticipateNew=arr[1]/anticipate;
            c=new Caculator(anticipateNew,arrNew);
            list=c.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[1]+"/("+str+")");
                }
            }
        }
        
        if(arr.length==4){
            this.anticipate=anticipate;// C
            
            double[] arrNew;// A
            double anticipateNew;// arr[2]=B
            List<String> list;
            Caculator cac;
            fomulaList=new ArrayList<String>();
            
            /// 0,1,2 &3
            // A+B=C 
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate-arr[3];
            cac=new Caculator(anticipateNew,arrNew);
            
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")+"+arr[3]);
                }
            }
            
            // A-B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate+arr[3];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")-"+arr[3]);
                }
            }
            
            // B-A=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[2];
            
            anticipateNew=arr[3]-anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[3]+"-("+str+")");
                }
            }
            
            // A*B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate/arr[3];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")*"+arr[3]);
                }
            }
            
            // A/B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate*arr[3];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")/"+arr[3]);
                }
            }
            
            // B/A=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[2];
            
            anticipateNew=arr[3]/anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[3]+"/("+str+")");
                }
            }
            
            /// 0,1,3 & 2
            // A+B=C 
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate-arr[2];
            cac=new Caculator(anticipateNew,arrNew);
            
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")+"+arr[2]);
                }
            }
            
            // A-B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate+arr[2];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")-"+arr[2]);
                }
            }
            
            // B-A=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[3];
            
            anticipateNew=arr[2]-anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[2]+"-("+str+")");
                }
            }
            
            // A*B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate/arr[2];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")*"+arr[2]);
                }
            }
            
            // A/B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate*arr[2];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")/"+arr[2]);
                }
            }
            
            // B/A=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[1];
            arrNew[2]=arr[3];
            
            anticipateNew=arr[2]/anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[2]+"/("+str+")");
                }
            }
            
            /// 0,3,2&1
            // A+B=C 
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[3];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate-arr[1];
            cac=new Caculator(anticipateNew,arrNew);
            
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")+"+arr[1]);
                }
            }
            
            // A-B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[3];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate+arr[1];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")-"+arr[1]);
                }
            }
            
            // B-A=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[3];
            arrNew[2]=arr[2];
            
            anticipateNew=arr[1]-anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[1]+"-("+str+")");
                }
            }
            
            // A*B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[3];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate/arr[1];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")*"+arr[1]);
                }
            }
            
            // A/B=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[3];
            arrNew[2]=arr[2];
            
            anticipateNew=anticipate*arr[1];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")/"+arr[1]);
                }
            }
            
            // B/A=C
            arrNew=new double[3];
            arrNew[0]=arr[0];
            arrNew[1]=arr[3];
            arrNew[2]=arr[2];
            
            anticipateNew=arr[1]/anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[1]+"/("+str+")");
                }
            }
            
            /// 1,2,3&0
            // A+B=C 
            arrNew=new double[3];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate-arr[0];
            cac=new Caculator(anticipateNew,arrNew);
            
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")+"+arr[0]);
                }
            }
            
            // A-B=C
            arrNew=new double[3];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate+arr[0];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")-"+arr[0]);
                }
            }
            
            // B-A=C
            arrNew=new double[3];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            arrNew[2]=arr[3];
            
            anticipateNew=arr[0]-anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[0]+"-("+str+")");
                }
            }
            
            // A*B=C
            arrNew=new double[3];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate/arr[0];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")*"+arr[0]);
                }
            }
            
            // A/B=C
            arrNew=new double[3];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            arrNew[2]=arr[3];
            
            anticipateNew=anticipate*arr[0];
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add("("+str+")/"+arr[0]);
                }
            }
            
            // B/A=C
            arrNew=new double[3];
            arrNew[0]=arr[1];
            arrNew[1]=arr[2];
            arrNew[2]=arr[3];
            
            anticipateNew=arr[0]/anticipate;
            cac=new Caculator(anticipateNew,arrNew);
            list=cac.fomulaList;
            if(list.size()>0){
                for(String str:list){
                    fomulaList.add(arr[0]+"/("+str+")");
                }
            }
            
            // 两个两组的
            if(isEqual(arr[0]*arr[1]+arr[2]*arr[3],anticipate)){
                fomulaList.add(arr[0]+"*"+arr[1]+"+"+arr[2]+"*"+arr[3]);
            }
            
            if(isEqual(arr[0]*arr[1]-arr[2]*arr[3],anticipate)){
                fomulaList.add(arr[0]+"*"+arr[1]+"-"+arr[2]+"*"+arr[3]);
            }
            
            if(isEqual(arr[2]*arr[3]-arr[0]*arr[1],anticipate)){
                fomulaList.add(arr[2]+"*"+arr[3]+"-"+arr[0]+"*"+arr[1]);
            }
            
            
            if(isEqual(arr[0]/arr[1]+arr[2]/arr[3],anticipate)){
                fomulaList.add(arr[0]+"/"+arr[1]+"+"+arr[2]+"/"+arr[3]);
            }
            if(isEqual(arr[0]/arr[1]-arr[2]/arr[3],anticipate)){
                fomulaList.add(arr[0]+"/"+arr[1]+"-"+arr[2]+"/"+arr[3]);
            }
            if(isEqual(arr[2]/arr[3]-arr[0]/arr[1],anticipate)){
                fomulaList.add(arr[2]+"/"+arr[3]+"-"+arr[0]+"/"+arr[1]);
            }
            
            if(isEqual(arr[0]/arr[2]+arr[1]/arr[3],anticipate)){
                fomulaList.add(arr[0]+"/"+arr[2]+"+"+arr[1]+"/"+arr[3]);
            }
            if(isEqual(arr[0]/arr[2]-arr[1]/arr[3],anticipate)){
                fomulaList.add(arr[0]+"/"+arr[2]+"-"+arr[1]+"/"+arr[3]);
            }
            if(isEqual(arr[1]/arr[3]-arr[0]/arr[2],anticipate)){
                fomulaList.add(arr[1]+"/"+arr[3]+"-"+arr[0]+"/"+arr[2]);
            }
            
            if(isEqual(arr[0]/arr[3]+arr[1]/arr[2],anticipate)){
                fomulaList.add(arr[0]+"/"+arr[3]+"+"+arr[1]+"/"+arr[2]);
            }
            if(isEqual(arr[0]/arr[3]-arr[1]/arr[2],anticipate)){
                fomulaList.add(arr[0]+"/"+arr[3]+"-"+arr[1]+"/"+arr[2]);
            }
            if(isEqual(arr[1]/arr[2]-arr[0]/arr[3],anticipate)){
                fomulaList.add(arr[1]+"/"+arr[2]+"-"+arr[0]+"/"+arr[3]);
            }
        }
    }
    
    public void printFomula(){
        if(fomulaList!=null && fomulaList.size()>0){
            Set<String> set=new HashSet<String>();
            set.addAll(fomulaList);
            
            for(String str:set){
                System.out.println(str+"="+anticipate);
            }
        }else{
            // System.out.println("无解"); //
        }
    }
    
    // 判断两个数是否相等
    private static boolean isEqual(double d1,double d2){
        return Math.abs(d1-d2)<0.0001;
    }
    
    /**
     * 两个数进行四则运算的六种结果
     * @return
     */
    private List<String> getFomulaList(){
        List<String> retval=new ArrayList<String>();
        
        if(isEqual(op1-op2,anticipate)){
            retval.add(op1+"-"+op2);
        }
        
        if(isEqual(op2-op1,anticipate)){
            retval.add(op2+"-"+op1);
        }
        
        if(isEqual(op1+op2,anticipate)){
            retval.add(op1+"+"+op2);
        }
        
        if(isEqual(op1*op2,anticipate)){
            retval.add(op1+"*"+op2);
        }
        
        if(isEqual(op1/op2,anticipate)){
            retval.add(op1+"/"+op2);
        }
        
        if(isEqual(op2/op1,anticipate)){
            retval.add(op2+"/"+op1);
        }
        
        return retval;
    }
    
    public static void main(String[] args){
        double[] arr1={3,6,9,12};
        Caculator c1=new Caculator(24,arr1);
        c1.printFomula();
        
        System.out.println("-----------");
        
        List<double[]> list=new ArrayList<double[]>();
        list.add(new double[]{});
        

        list.add(new double[] { 8, 3, 3, 8 });
        list.add(new double[] { 3, 7, 3, 7 });
        list.add(new double[] { 12, 12, 12, 10 });
        list.add(new double[] { 10, 10, 4, 4 });
        list.add(new double[] { 1, 4, 5, 6 });
        list.add(new double[] { 2, 2, 2, 9 });
        list.add(new double[] { 3, 4, 7, 8 });
        list.add(new double[] { 11, 11, 1, 5 });
        list.add(new double[] { 1, 2, 7, 7 });
        list.add(new double[] { 7, 7, 4, 4 });
        list.add(new double[] { 1, 4, 5, 6 });
        list.add(new double[] { 1, 3, 4, 6 });
        list.add(new double[] { 5, 5, 5, 1 });
        
        for(double[] arr:list){
            Caculator c=new Caculator(arr);
            c.printFomula();
        }
        
    }
}
复制代码

输出:

复制代码
6.0/((9.0/12.0)/3.0)=24.0
12.0/((9.0/6.0)/3.0)=24.0
((3.0*12.0)/9.0)*6.0=24.0
(12.0/(9.0/6.0))*3.0=24.0
(12.0/(9.0/3.0))*6.0=24.0
12.0-(3.0-(6.0+9.0))=24.0
((12.0-3.0)+6.0)+9.0=24.0
((3.0+9.0)*12.0)/6.0=24.0
((3.0*12.0)*6.0)/9.0=24.0
((3.0/9.0)*12.0)*6.0=24.0
(6.0/(9.0/3.0))*12.0=24.0
((3.0*6.0)/9.0)*12.0=24.0
9.0-(3.0-(6.0+12.0))=24.0
((12.0-3.0)+9.0)+6.0=24.0
((6.0/9.0)*12.0)*3.0=24.0
((9.0-3.0)*6.0)-12.0=24.0
((9.0-3.0)+6.0)+12.0=24.0
12.0-((3.0-9.0)-6.0)=24.0
((3.0/9.0)*6.0)*12.0=24.0
((12.0+9.0)-3.0)+6.0=24.0
6.0-(3.0-(12.0+9.0))=24.0
((3.0+9.0)/6.0)*12.0=24.0
(9.0-(3.0-12.0))+6.0=24.0
((3.0*6.0)*12.0)/9.0=24.0
((6.0-3.0)+12.0)+9.0=24.0
12.0/(6.0/(3.0+9.0))=24.0
((6.0-3.0)+9.0)+12.0=24.0
((12.0/9.0)*6.0)*3.0=24.0
12.0-((3.0-6.0)-9.0)=24.0
6.0-((3.0-9.0)-12.0)=24.0
9.0-((3.0-12.0)-6.0)=24.0
((6.0/9.0)*3.0)*12.0=24.0
((9.0+12.0)+6.0)-3.0=24.0
3.0/((9.0/12.0)/6.0)=24.0
(6.0-(3.0-12.0))+9.0=24.0
((12.0/9.0)*3.0)*6.0=24.0
(3.0/(9.0/12.0))*6.0=24.0
((9.0-3.0)+12.0)+6.0=24.0
(3.0/(9.0/6.0))*12.0=24.0
((6.0*12.0)*3.0)/9.0=24.0
12.0/(9.0/(3.0*6.0))=24.0
(6.0-(3.0-9.0))+12.0=24.0
((6.0+12.0)+9.0)-3.0=24.0
((6.0+9.0)+12.0)-3.0=24.0
12.0/((9.0/3.0)/6.0)=24.0
6.0/(9.0/(3.0*12.0))=24.0
((6.0*12.0)/9.0)*3.0=24.0
6.0-((3.0-12.0)-9.0)=24.0
(9.0-(3.0-6.0))+12.0=24.0
3.0/(9.0/(6.0*12.0))=24.0
9.0-((3.0-6.0)-12.0)=24.0
((6.0+12.0)-3.0)+9.0=24.0
(12.0-(3.0-9.0))+6.0=24.0
6.0/((9.0/3.0)/12.0)=24.0
(6.0/(9.0/12.0))*3.0=24.0
(12.0-(3.0-6.0))+9.0=24.0
((6.0+9.0)-3.0)+12.0=24.0
3.0/((9.0/6.0)/12.0)=24.0
-----------
8.0/(3.0-(8.0/3.0))=24.0
((3.0/7.0)+3.0)*7.0=24.0
12.0*12.0-12.0*10.0=24.0
((10.0*10.0)-4.0)/4.0=24.0
6.0/((5.0/4.0)-1.0)=24.0
4.0/(1.0-(5.0/6.0))=24.0
((2.0+9.0)*2.0)+2.0=24.0
((9.0+2.0)*2.0)+2.0=24.0
8.0-((3.0-7.0)*4.0)=24.0
((7.0-3.0)*4.0)+8.0=24.0
((11.0*11.0)-1.0)/5.0=24.0
((7.0*7.0)-1.0)/2.0=24.0
(4.0-(4.0/7.0))*7.0=24.0
6.0/((5.0/4.0)-1.0)=24.0
4.0/(1.0-(5.0/6.0))=24.0
6.0/(1.0-(3.0/4.0))=24.0
(5.0-(1.0/5.0))*5.0=24.0
复制代码

 










本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/xiandedanteng/p/3874030.html,如需转载请自行联系原作者



相关文章
【C国演义】第一章
一堆数字里面,有且仅有一个数字出现的次数是奇数次,其他的数字出现的次数全为偶数次,求出这个数字(要求时间复杂度O(N))
|
人工智能 iOS开发 Windows
(待补充)小蒟蒻的刷题成长之路-------中国高校计算机大赛-团队程序设计天梯赛(GPLT)上海理工大学校内选拔赛(同步赛)
(待补充)小蒟蒻的刷题成长之路-------中国高校计算机大赛-团队程序设计天梯赛(GPLT)上海理工大学校内选拔赛(同步赛)
136 0
|
IDE Java 编译器
《C游记》 第一章 - 灵根孕育源流出 初识C言大道生(壹)
《C游记》 第一章 - 灵根孕育源流出 初识C言大道生(壹)
155 0
《C游记》 第一章 - 灵根孕育源流出 初识C言大道生(壹)
|
C语言 C++
《C游记》 第一章 - 灵根孕育源流出 初识C言大道生(贰)
《C游记》 第一章 - 灵根孕育源流出 初识C言大道生(贰)
194 0
《C游记》 第一章 - 灵根孕育源流出 初识C言大道生(贰)