提示不要了,最好有能copy 了就能用的,谢了,急用。

解决方案 »

  1.   

    给你一个c的
    修改一下就可以了#include <stdio.h>
    #include <stdlib.h>
    #include <memory.h>
    #include <malloc.h>
    #define MAX 4
    #define RESULT 24
    //int a[MAX]={5,4,3,2};//&Ocirc;&shy;&Ecirc;&frac14;&Ecirc;&yacute;&frac34;&Yacute;
    int a[MAX]={4,6,1,2};
    int A[MAX];//&sup2;&Eacute;&Oacute;&Atilde;&micro;&Auml;&Ecirc;&yacute;&frac34;&Yacute;&Iuml;à&micro;±&Oacute;&Uacute;stack
    int b[MAX];//&sup2;&raquo;&Iacute;&not;&sup2;&atilde;&acute;&Icirc;&pound;&not;&para;&Ocirc;&Oacute;&euml;a&Ouml;&ETH;&Ecirc;&yacute;&frac34;&Yacute;&Ecirc;&Ccedil;·&ntilde;&Ograve;&Ntilde;&frac34;&shy;&Ecirc;&sup1;&Oacute;&Atilde;
    char c[MAX];//±&pound;&acute;&aelig;·&ucirc;&ordm;&Aring;
    int bFound;//&Ecirc;&Ccedil;·&ntilde;·&cent;&Iuml;&Ouml;
    int bPrev=0;
    void tf(float x,int l);//&frac12;&oslash;&ETH;&ETH;&Euml;&Auml;&Ouml;&Ouml;&Ocirc;&Euml;&Euml;&atilde;
    void out(float y,int l);//&Aring;&ETH;&para;&Iuml;&Ecirc;&Ccedil;&frac14;&Igrave;&ETH;&oslash;&Ocirc;&Euml;&Euml;&atilde;&pound;&not;&raquo;&sup1;&Ecirc;&Ccedil;&Ecirc;&auml;&sup3;&ouml;&frac12;á&sup1;&ucirc;
    char *PFormat();
    int main(int argc, char* argv[])
    {    int i;
        for(i=0;i<MAX;i++)//&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;
            A[i]=0;
        bFound=0;    tf(0,0);
        if(bFound==0)
        {
            printf("\n&Atilde;&raquo;&Oacute;&ETH;·&cent;&Iuml;&Ouml;");
        }
        getchar();    return 0;
    }
    void tf(float x,int l)
    //x,&Eacute;&Iuml;&Ograve;&raquo;&acute;&Icirc;&Ocirc;&Euml;&Euml;&atilde;&micro;&Auml;&frac12;á&sup1;&ucirc;
    //l,&micro;±&Ccedil;°&Euml;ù&Ocirc;&Uacute;&Ocirc;&Euml;&Euml;&atilde;&micro;&Auml;&sup2;&frac12;&Ecirc;&yacute;&pound;&not;&Ograve;&sup2;&frac14;&acute;&sup2;&atilde;&acute;&Icirc;
    {
        int i;
        float y;
        int B[MAX];
        for(i=0;i<MAX;i++)
            B[i]=0;
        for(i=0;i<MAX;i++)
        {
            if(b[i]==0 && B[i]==0)
            {
                A[l]=a[i];
                b[i]=1;
                B[i]=1;
                if(l==0)//&sup2;&atilde;&acute;&Icirc;&Icirc;&ordf;0&pound;&not;&Icirc;&ordf;&micro;&Uacute;&Ograve;&raquo;&cedil;&ouml;&Ecirc;&yacute;
                {
                    c[l]=' ';
                    y=a[i];
                    out(y,l+1);
                }
                else{
                    c[l]='+';
                    y=x+a[i];
                    out(y,l+1);
                    c[l]='-';
                    y=x-a[i];
                    out(y,l+1);
                    c[l]='*';
                    y=x*a[i];
                    out(y,l+1);
                    c[l]='/';
                    y=x/a[i];
                    out(y,l+1);
                }
                b[i]=0;        }
        }}
    void out(float y,int l)
    //y,&Eacute;&Iuml;&Ograve;&raquo;&acute;&Icirc;&Ocirc;&Euml;&Euml;&atilde;&micro;&Auml;&frac12;á&sup1;&ucirc;
    //l,&micro;±&Ccedil;°&Euml;ù&Ocirc;&Uacute;&Ocirc;&Euml;&Euml;&atilde;&micro;&Auml;&sup2;&frac12;&Ecirc;&yacute;&pound;&not;&Ograve;&sup2;&frac14;&acute;&sup2;&atilde;&acute;&Icirc;
    {
        int i;
        char *p;
        if(l==MAX)//&sup2;&atilde;&acute;&Icirc;&Icirc;&ordf;MAX,&Ograve;&Ntilde;&Ocirc;&Euml;&Euml;&atilde;&micro;&frac12;×&icirc;&ordm;ó&pound;&not;&sup2;&raquo;&ETH;è&frac14;&Igrave;&ETH;&oslash;
        {
            if(y==RESULT)//&frac12;á&sup1;&ucirc;&para;&Ocirc;&Acirc;&eth;&pound;&iquest;
            {
                bFound=1;
                printf("\nFound\n");
                //          for(i=0;i<MAX;i++)
                //          {
                //
                //          printf(" %c %d",c[i],A[i]);
                //          }
                p=PFormat();
                printf("%s=%d",p,RESULT);//&cedil;&ntilde;&Ecirc;&frac12;&raquo;&macr;&Ecirc;&auml;&sup3;&ouml;            getchar();
            }
        }
        else
        {
                tf(y,l);//&frac14;&Igrave;&ETH;&oslash;&Ocirc;&Euml;&Euml;&atilde;
        }}
    //&cedil;&ntilde;&Ecirc;&frac12;&raquo;&macr;&Ecirc;&auml;&sup3;&ouml;
    //&micro;±&Oacute;&Eacute;+,-×&ordf;&Iuml;ò*,/&ETH;è&Ograve;&ordf;&frac14;&Oacute;()
    char * PFormat()
    {    char tmp[1024];
        //(char *)malloc((MAX-2)*2);
        static  char s[1024];
        //=(char *)malloc((MAX-2)*2);
        int i;
        memset(tmp,0x00,sizeof(tmp));
        memset(s,0x00,sizeof(s));
        for(i=0;i<MAX;i++)
        {        if(c[i]=='+'|c[i]=='-')
            {
                bPrev=0;
                sprintf(tmp,"%s",s);
            }
            else if (bPrev==0 && (c[i]=='*' || c[i]=='/'))//&Oacute;&Aring;&Iuml;&Egrave;&cedil;&Auml;±&auml;
            {
                sprintf(tmp,"(%s)",s);
                bPrev=1;
            }
            else
            {
                sprintf(tmp,"%s",s);
                bPrev=1;
            }            sprintf(s,"%s %c %d ",tmp,c[i],A[i]);
        }    return s;
    }
      

  2.   

    我以前写过一个,是用for 计算从第一个字母到第四个字母,中间在嵌套括号的3个位置
    所有计算完后在递归3次计算运算符,不难,但是工作量太大,我好象已经删除了,帮你找找,记得光是那个b/0的异常抛出就有50多个
      

  3.   

    import java.util.Vector;
    import java.util.Enumeration ;
    public class Solution
    {    static Vector numbers;
        boolean hasSolution;
        Vector theSolution;
        Vector allSolution;
        double theResult;
        static final int TOTAL_POSITION = 13;
        static final int NUM_POSITION[] = {
            1, 4, 8, 11
        };
        static int numCombin[][] = new int[24][4];
        static boolean hasNumCombin = false;
        static final int OP_POSITION[] = {
            2, 6, 10
        };
        static int opCombin[][] = new int[64][3];
        static boolean hasOpCombin = false;
        static Character whiteSpace = new Character(' ');
        static Character openParen = new Character('(');
        static Character closeParen = new Character(')');
        static Character addition = new Character('+');
        static Character subtract = new Character('-');
        static Character multiply = new Character('*');
        static Character division = new Character('/');
        static final int PAREN_POSITION[] = {
            0, 3, 5, 7, 9, 12
        };
        static final int PAREN_COMBIN[][] = {
            {
                0, 0, 0, 0, 0, 0
            }, {
                1, 0, 2, 0, 0, 0
            }, {
                1, 0, 0, 0, 2, 0
            }, {
                0, 1, 0, 0, 2, 0
            }, {
                0, 1, 0, 0, 0, 2
            }, {
                0, 0, 0, 1, 0, 2
            }, {
                1, 0, 2, 1, 0, 2
            }
        };    public Solution(int num0, int num1, int num2, int num3)
        {
            theSolution = null;
            allSolution = null;
            numbers = new Vector(4);
            numbers.addElement(new Integer(num0));
            numbers.addElement(new Integer(num1));
            numbers.addElement(new Integer(num2));
            numbers.addElement(new Integer(num3));
            searchSolution();
        }    public Vector getSolution()
        {
            return theSolution;
        }
         public Vector getAllSolution()
        {
            return allSolution;
        }
        public boolean hasSolution()
        {
            return hasSolution;
        }    private static void numberCombination()
        {
            Vector numbers = new Vector(4);
            int count = 0;
            if(hasNumCombin)
                return;
            for(int i = 0; i < 4; i++)
                numbers.addElement(new Integer(i));        for(int i = 0; i < 4; i++)
            {
                for(int j = 0; j < 3; j++)
                {
                    for(int k = 0; k < 2; k++)
                    {
                        Vector tmpNumbers = (Vector)numbers.clone();
                        numCombin[count][0] = ((Integer)tmpNumbers.elementAt(i)).intValue();
                        tmpNumbers.removeElementAt(i);
                        numCombin[count][1] = ((Integer)tmpNumbers.elementAt(j)).intValue();
                        tmpNumbers.removeElementAt(j);
                        numCombin[count][2] = ((Integer)tmpNumbers.elementAt(k)).intValue();
                        tmpNumbers.removeElementAt(k);
                        numCombin[count][3] = ((Integer)tmpNumbers.elementAt(0)).intValue();
                        tmpNumbers.removeElementAt(0);
                        count++;
                    }            }        }        hasNumCombin = true;
        }    private static void operatorCombination()
        {
            int count = 0;
            if(hasOpCombin)
                return;
            for(int i = 0; i < 4; i++)
            {
                for(int j = 0; j < 4; j++)
                {
                    for(int k = 0; k < 4; k++)
                    {
                        opCombin[count][0] = i;
                        opCombin[count][1] = j;
                        opCombin[count][2] = k;
                        count++;
                    }            }        }        hasOpCombin = true;
        }    public void haveRest(int time)
        {
            try
            {
                Thread.sleep(time);
            }
            catch(InterruptedException interruptedexception) { }
        }    private void searchSolution()
        {
            Vector tmpExpression = new Vector(13);
            Vector tmpAllExpression = new Vector(10);
            hasSolution = false;
            theSolution = null;
            int count = 0;
            numberCombination();
            operatorCombination();
            for(int i = 0; i < 13; i++)
                tmpExpression.addElement(whiteSpace);        for(int num = 0; num < 24; num++)
            {
                for(int paren = 0; paren < 7; paren++)
                {
                    for(int op = 0; op < 64; op++)
                    {
                        if(count++ % 500 == 0)
                            haveRest(100);
                        for(int i = 0; i < 4; i++)
                            tmpExpression.setElementAt(numbers.elementAt(numCombin[num][i]), NUM_POSITION[i]);                    for(int i = 0; i < 6; i++)
                            switch(PAREN_COMBIN[paren][i])
                            {
                            case 1: 
                                tmpExpression.setElementAt(openParen, PAREN_POSITION[i]);
                                break;                        case 2: 
                                tmpExpression.setElementAt(closeParen, PAREN_POSITION[i]);
                                break;                        case 0: 
                                tmpExpression.setElementAt(whiteSpace, PAREN_POSITION[i]);
                                break;
                            }                    for(int i = 0; i < 3; i++)
                            switch(opCombin[op][i])
                            {
                            case 0: 
                                tmpExpression.setElementAt(addition, OP_POSITION[i]);
                                break;                        case 1: 
                                tmpExpression.setElementAt(subtract, OP_POSITION[i]);
                                break;                        case 2: 
                                tmpExpression.setElementAt(multiply, OP_POSITION[i]);
                                break;                        case 3: 
                                tmpExpression.setElementAt(division, OP_POSITION[i]);
                                break;
                            }                    try
                        {
                            theResult = (new Expression(tmpExpression)).getValue();
                        }
                        catch(IllegalExpressionException e)
                        {
                            continue;
                        }
                        if(theResult == 24D)
                        {
                            hasSolution = true;
                            theSolution = tmpExpression;
                            tmpAllExpression.addElement(tmpExpression.clone());
                            allSolution=tmpAllExpression;
                        }
                    }            }        }        
        }    void printSolution()
        {
         if(hasSolution())
         {
           Enumeration em=allSolution.elements();
           while(em.hasMoreElements())
           {
            Vector ve = (Vector)em.nextElement();
            for(int i=0; i<ve.size();i++)
            {
             if(ve.elementAt(i) instanceof Integer)
            {
               System.out.print((Integer)ve.elementAt(i));
                    }  
                    else
                    {
                     if((ve.elementAt(i)) instanceof Character && !whiteSpace.equals((ve.elementAt(i))))
                     {
                        System.out.print((Character)ve.elementAt(i));
                     }
                    } 
            }
            System.out.println("=24");
           
           }
         }
         else
         {
            System.out.println("err or NO Solution!");
         }
        }
         public static void main(String args[])
        {
         Solution s24=new Solution(Integer.parseInt(args[0]),Integer.parseInt(args[1]),Integer.parseInt(args[2]),Integer.parseInt(args[3]));
         s24.printSolution();
        
        }
    }
      

  4.   

    #include<iostream>
    #include<string>
    #include<vector>
    #include<set>
    using namespace std;
    set<string>vs;
    //author: JLU_faen of software
    string gc(int n)
    {
    string s;
    bool tag=false;
    if(n<0){tag=true;n=-n;}
    if(n==0){s="0";return s;}
    while(n)
    {
        s=char(n%10+'0')+s;
        n/=10;
        }
        if(tag)s='-'+s;    
    return s;
    }
    void g(vector<int> vi,string s)
    {
    if(vi.size()==1)
    if(vi[0]==24)
    {
    vs.insert(s);
    return;
    }
    else return;
    for(int i=0;i<vi.size();i++)
    for(int j=i+1;j<vi.size();j++)
    {
        //if(j==i)continue;
    vector<int>vit;
    string snext;
    for(int k=0;k<vi.size();k++)
    if(k!=i&&k!=j)
    vit.push_back(vi[k]);

    vit.push_back(vi[i]+vi[j]);
    snext=s+"   "+gc(vi[i])+"+"+gc(vi[j])+"="+gc(vi[i]+vi[j]);
    g(vit,snext);
    snext="";
    vit.pop_back(); vit.push_back(vi[i]-vi[j]);
    snext=s+"   "+gc(vi[i])+"-"+gc(vi[j])+"="+gc(vi[i]-vi[j]);
    g(vit,snext);
    vit.pop_back();
    snext=""; vit.push_back(vi[i]*vi[j]);
    snext=s+"   "+gc(vi[i])+"*"+gc(vi[j])+"="+gc(vi[i]*vi[j]);
    g(vit,snext);
    vit.pop_back();
    snext=""; if(vi[j]&&vi[i]%vi[j]==0)
    {
    vit.push_back(vi[i]/vi[j]);
    snext=s+"   "+gc(vi[i])+"/"+gc(vi[j])+"="+gc(vi[i]/vi[j]);
    g(vit,snext);
    vit.pop_back();
    snext="";
    }
    if(vi[i]&&vi[j]%vi[i]==0)
    {
    vit.push_back(vi[j]/vi[i]);
    snext=s+"   "+gc(vi[j])+"/"+gc(vi[i])+"="+gc(vi[j]/vi[i]);
    g(vit,snext);
    vit.pop_back();
    snext="";
    }
    }
    }
    int main()
    {
    int a,b,c,d;
    cout<<"please input four numbers:\n";
    cin>>a>>b>>c>>d;
    vector<int>vi;
    vi.push_back(a);
    vi.push_back(b);
    vi.push_back(c);
    vi.push_back(d);
    string s;
    g(vi,s);
    if(vs.size())
    {
    set<string>::iterator p=vs.begin();
    for(;p!=vs.end();p++)
    cout<<*p<<endl;
    }
    else
    cout<<"sorry the four numbers can't be done"<<endl;
    int aa;
    cin>>aa;
    return 0;
    }
      

  5.   

    谢谢发恩,要java 
    不好意思,没说清楚
      

  6.   

    public class Test24Point{
        public static void main(String[] args){
         int index = 0 ;
         int temp = 0 ;
         int totalSuc = 0 ;
        
         int numb[] = new int[4];//the first four numbers
         double num[][] = new double[36][3];//three numbers after calculating
         double total[] = new double[6];//the number after three steps of calculating
        
        
        
         double p[][] = new double[6][8];
         double q[][] = new double[3][7];
        
        
        
         //System.out.println(2465%108);
         //System.out.println(2465/108);
        
         System.out.println("\"a--b\"means\"b-a\"");
         System.out.println("\"a//b\"means\"b/a\"\n");
    for(int i = 0 ; i < 4 ; i ++){
    numb[i] = Integer.parseInt(args[i]);
    }
        
           for(int i = 0; i < 3; i ++)//Get two of the four to calculate and then store the new number into the array p;
           for(int j = i + 1; j < 4 ; j ++,temp ++){
           p[temp][0] = numb[i] + numb[j]; 
           p[temp][1] = numb[i] - numb[j];
           p[temp][2] = numb[j] - numb[i];
           p[temp][3] = numb[i] * numb[j];
           if(numb[j] != 0)
           p[temp][4] = numb[i] / (double)numb[j];
           else
           p[temp][4] = 10000;
           if(numb[i] != 0)
           p[temp][5] = numb[j] / (double)numb[i];
           else
           p[temp][5] = 10000;
          
          
         
          switch(temp){
          case 0:p[temp][6] = numb[2]; p[temp][7] = numb[3];break;
          case 1:p[temp][6] = numb[1]; p[temp][7] = numb[3];break;
          case 2:p[temp][6] = numb[1]; p[temp][7] = numb[2];break;
          case 3:p[temp][6] = numb[0]; p[temp][7] = numb[3];break;
          case 4:p[temp][6] = numb[0]; p[temp][7] = numb[2];break;
          case 5:p[temp][6] = numb[0]; p[temp][7] = numb[1];
          }
         
          }
         
    for(int k = 0,tem = 0; k < 6; k ++)//Get the possible three numbers and store into the array num[36][3] for calculating .
    for(int l = 0; l < 6; l ++,tem ++){
    num[tem][0] = p[k][l] ;
    num[tem][1] = p[k][6] ;
    num[tem][2] = p[k][7] ;


    for(int t = 2,m = 0, n = 0,te = 0; t >= 0; t --,te ++){//Get two of the three to calculate and then store the new number into the array q; 
       m = (t + 1)%3;
       n = (t + 2)%3;
       q[te][6] = num[tem][t];
      
       q[te][0] = num[tem][m] + num[tem][n];
       q[te][1] = num[tem][m] - num[tem][n];
       q[te][2] = num[tem][n] - num[tem][m];
       q[te][3] = num[tem][m] * num[tem][n];
       if(num[tem][n] != 0)
       q[te][4] = num[tem][m] / (double)num[tem][n];
       else
       q[te][4] = 10000 ;
       if(num[tem][m] != 0)
       q[te][5] = num[tem][n] / (double)num[tem][m];
       else
       q[te][5] = 10000 ;
       }
      
      

  7.   

    for(int u = 0; u < 3; u ++)
         for(int v = 0; v < 6; v ++){
         if(u == 2){//We must insure that the old value is in the left ,so the result string can be appended rightly.
         total[0] = q[u][6] + q[u][v];
         total[1] = q[u][6] - q[u][v];
         total[2] = q[u][v] - q[u][6];
         total[3] = q[u][v] * q[u][6];
         if(q[u][6] != 0)
         total[4] = q[u][6] / (double)q[u][v];
         else
         total[4] = 10000;
         if(q[u][v] != 0)
         total[5] = q[u][v] / (double)q[u][6];
         else
         total[5] = 10000;
         }
         else{
         total[0] = q[u][v] + q[u][6];
         total[1] = q[u][v] - q[u][6];
         total[2] = q[u][6] - q[u][v];
         total[3] = q[u][v] * q[u][6];
         if(q[u][6] != 0)
         total[4] = q[u][v] / (double)q[u][6];
         else
         total[4] = 10000;
         if(q[u][v] != 0)
         total[5] = q[u][6] / (double)q[u][v];
         else
         total[5] = 10000;
         }
        
         for(int s = 0 ; s < 6 ; s ++){
         if(total[s]>23.9999&&total[s]<24.0001){
         //System.out.println("24!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
         totalSuc ++ ;
         //print the expression
    char x[] = new char[3];
    int n0 = index ;
    String expre = "" ;
    String expre1 = "" ;
    int n1 = index/108;//the first composition and its operator.
    int n2 = index%108/6;//the second composition and its operator.
    int n3 = index%6;//the last operator.

    if(index == 3321){System.out.println(q[2][1] + " " +q[2][6]);}

    switch(n1){
         
          case 0:expre += "((a+b)";x[1]='c';x[2]='d';break;
          case 1:expre += "((a-b)";x[1]='c';x[2]='d';break;
          case 2:expre += "((b-a)";x[1]='c';x[2]='d';break;
          case 3:expre += "((a*b)";x[1]='c';x[2]='d';break;
          case 4:expre += "((a/b)";x[1]='c';x[2]='d';break;
          case 5:expre += "((b/a)";x[1]='c';x[2]='d';break;
          case 6:expre += "((a+c)";x[1]='b';x[2]='d';break;
          case 7:expre += "((a-c)";x[1]='b';x[2]='d';break;
          case 8:expre += "((c-a)";x[1]='b';x[2]='d';break;
          case 9:expre += "((a*c)";x[1]='b';x[2]='d';break;
          case 10:expre += "((a/c)";x[1]='b';x[2]='d';break;
          case 11:expre += "((c/a)";x[1]='b';x[2]='d';break;
          case 12:expre += "((a+d)";x[1]='b';x[2]='c';break;
          case 13:expre += "((a-d)";x[1]='b';x[2]='c';break;
          case 14:expre += "((d-a)";x[1]='b';x[2]='c';break;
          case 15:expre += "((a*d)";x[1]='b';x[2]='c';break;
          case 16:expre += "((a/d)";x[1]='b';x[2]='c';break;
          case 17:expre += "((d/a)";x[1]='b';x[2]='c';break;
          case 18:expre += "((b+c)";x[1]='a';x[2]='d';break;
          case 19:expre += "((b-c)";x[1]='a';x[2]='d';break;
          case 20:expre += "((c-b)";x[1]='a';x[2]='d';break;
          case 21:expre += "((b*c)";x[1]='a';x[2]='d';break;
          case 22:expre += "((b/c)";x[1]='a';x[2]='d';break;
          case 23:expre += "((c/b)";x[1]='a';x[2]='d';break;
          case 24:expre += "((b+d)";x[1]='a';x[2]='c';break;
          case 25:expre += "((b-d)";x[1]='a';x[2]='c';break;
          case 26:expre += "((d-b)";x[1]='a';x[2]='c';break;
          case 27:expre += "((b*d)";x[1]='a';x[2]='c';break;
          case 28:expre += "((b/d)";x[1]='a';x[2]='c';break;
          case 29:expre += "((d/b)";x[1]='a';x[2]='c';break;
          case 30:expre += "((c+d)";x[1]='a';x[2]='b';break;
          case 31:expre += "((c-d)";x[1]='a';x[2]='b';break;
          case 32:expre += "((d-c)";x[1]='a';x[2]='b';break;
          case 33:expre += "((c*d)";x[1]='a';x[2]='b';break;
          case 34:expre += "((c/d)";x[1]='a';x[2]='b';break;
          case 35:expre += "((d/c)";x[1]='a';x[2]='b';
          }
         
          switch(n2){
         
          case 0:expre += "+" +x[1] +")";x[1]=x[2];break;//x[0] and x[1].
          case 1:expre += "-" +x[1] +")";x[1]=x[2];break;
          case 2:expre += "--" +x[1] +")";x[1]=x[2];break;
          case 3:expre += "*" +x[1] +")";x[1]=x[2];break;
          case 4:expre += "/" +x[1] +")";x[1]=x[2];break;
          case 5:expre += "//" +x[1] +")";x[1]=x[2];break;
         
          case 6:expre += "+" +x[2] +")";x[1]=x[1];break;//x[2] and x[0].
          case 7:expre += "--" +x[2] +")";x[1]=x[1];break;
          case 8:expre += "-" +x[2] +")";x[1]=x[1];break;
          case 9:expre += "*" +x[2] +")";x[1]=x[1];break;
          case 10:expre += "//" +x[2] +")";x[1]=x[1];break;
          case 11:expre += "/" +x[2] +")";x[1]=x[1];break;
         
          case 12:expre1 += x[1] + "+" + x[2] +"))";x[1]='(';break;//x[1] and x[2].
          case 13:expre1 += x[1] + "-" + x[2] +"))";x[1]='(';break;
          case 14:expre1 += x[1] + "--" + x[2] +"))";x[1]='(';break;
          case 15:expre1 += x[1] + "*" + x[2] +"))";x[1]='(';break;
          case 16:expre1 += x[1] + "/" + x[2] +"))";x[1]='(';break;
          case 17:expre1 += x[1] + "//" + x[2] +"))";x[1]='(';
          }
         
          switch(n3){
         
          case 0:expre += "+" +x[1] + expre1;break;
          case 1:expre += "-" +x[1] + expre1;break;
          case 2:expre += "--" +x[1] + expre1;break;
          case 3:expre += "*" +x[1] + expre1;break;
          case 4:expre += "/" +x[1] + expre1;break;
          case 5:expre += "//" +x[1] + expre1;
          }
          expre = expre.replace('a',(char)(numb[0] + 48));
          expre = expre.replace('b',(char)(numb[1] + 48));
          expre = expre.replace('c',(char)(numb[2] + 48));
          expre = expre.replace('d',(char)(numb[3] + 48));
         
          System.out.println(expre+"  ");
         }
         //System.out.println("total : " + total[s] + " index :" +"\n\n");
        
         
           index ++ ;
    }

    }
         
         }System.out.println("The number of total successful expressions is : " + totalSuc);
    }
        
    }
      

  8.   

    import java.util.*;
    public class Suan24
    {
    private static HashSet<String>vs_r=new HashSet<String>();
    private static String gc(double n)
    {
    String s=""+n;
    StringBuffer t=new StringBuffer(s);
    for(int i=t.length()-1;i>=0;i--)
    if(t.charAt(i)=='0')
    t.setCharAt(i,' ');
    s=t.toString();
    s=s.trim();
    if(s.charAt(s.length()-1)=='.')
    return s.substring(0,s.length()-1);
    return s;
    }
    private static void f(LinkedList<Double>vi,LinkedList<String>vs)
    {
    if(vi.size()==1)
    if(vi.get(0)==24)
    {
    String t=vs.get(0);
    t=t.substring(1,t.length()-1);
    t+="=24";
    vs_r.add(new String(t));
    return;
    }
    else return;
    for(int i=0;i<vi.size();i++)
    for(int j=0;j<vi.size();j++)
    {
    if(i==j)continue;
    LinkedList<Double>vit=new LinkedList<Double>();
    LinkedList<String>vst=new LinkedList<String>();
    String s="";
    for(int k=0;k<vi.size();k++)
    if(k!=i&&k!=j)
    {
    vit.addLast(vi.get(k));
    vst.addLast(new String(vs.get(k)));
    }
    vit.addLast(vi.get(i)+vi.get(j));
    s="("+vs.get(i)+"+"+vs.get(j)+")";
    vst.addLast(new String(s));
    f(vit,vst);
    vst.removeLast();
    vit.removeLast();

    vit.addLast(vi.get(i)-vi.get(j));
    s="("+vs.get(i)+"-"+vs.get(j)+")";
    vst.addLast(new String(s));
    f(vit,vst);
    vst.removeLast();
    vit.removeLast();

    vit.addLast(vi.get(i)*vi.get(j));
    s="("+vs.get(i)+"*"+vs.get(j)+")";
    vst.addLast(new String(s));
    f(vit,vst);
    vst.removeLast();
    vit.removeLast();

    if(vi.get(j)!=0)
    {
    vit.addLast(vi.get(i)/vi.get(j));
    s="("+vs.get(i)+"/"+vs.get(j)+")";
    vst.addLast(new String(s));
    f(vit,vst);
    vst.removeLast();
    vit.removeLast();
    }
    }
    }
    public static void main(String [] args)
    {
    Double a,b,c,d;
    System.out.println("please input four numbers:");
    Scanner cin=new Scanner(System.in);
    a=cin.nextDouble();b=cin.nextDouble();c=cin.nextDouble();d=cin.nextDouble();
    LinkedList<Double>vi=new LinkedList<Double>();
    LinkedList<String>vs=new LinkedList<String>();
    vi.add(a);vs.add(gc(a));
    vi.add(b);vs.add(gc(b));
    vi.add(c);vs.add(gc(c));
    vi.add(d);vs.add(gc(d));
    f(vi,vs);
    if(vs_r.size()>0)
    {
    Iterator it=vs_r.iterator();
    while(it.hasNext())
    System.out.println(it.next());
    }
    else
    System.out.println("sorry the four numbers can't be done");
    }
    }