如题...各位高手请赐教

解决方案 »

  1.   

    (10*10-4)/4
    http://topic.csdn.net/u/20100317/21/0bcd91cf-88ca-44c6-819b-ab5cddafe8fe.html
      

  2.   

    6 ? 8 ? 10 ? 12=246 + 8 + 10 + 12 =   0 0 0
    6 + 8 + 10 - 12 =   0 0 1
    6 + 8 + 10 * 12 =   0 0 2
    6 + 8 + 10 / 12 =   0 0 36 + 8 - 10 + 12 =   0 1 0
    6 + 8 - 10 - 12 =   0 1 1
    6 + 8 - 10 * 12 =   0 1 2
    6 + 8 - 10 / 12 =   0 1 36 + 8 * 10 + 12 =   0 2 0
    8 + 8 * 10 - 12 =   0 2 1
    6 + 8 * 10 * 12 =   0 2 2
    6 + 8 * 10 / 12 =   0 2 36 + 8 / 10 + 12 =   0 3 0
    6 + 8 / 10 - 12 =   0 3 1
    6 + 8 / 10 * 12 =   0 3 2
    6 + 8 / 10 / 12 =   0 3 34 * 4 * 4 = 64-----------------------------------
    6 ? 8 ? 10 ? 12 = 24
    10 ? 8 ? 6 ? 12 = 24
    10 ? 6 ? 8 ? 12 = 24
    8 ? 6 ? 10 ? 12 = 24
    8 ? 10 ? 6 ? 12 = 24
    6 ? 10 ? 8 ? 12 = 244 * 6 = 24-------------
    64 * 24 = 1536
    如果看不懂那你就别去研究了因为你没诚意,两个For套起来
      

  3.   

    private static void Main()
    {
        int num = int.Parse(Console.ReadLine());
        DataTable table = new DataTable();
        string[] strArray = new string[] { "{0:0.0}{1}{2:0.0}{3}{4:0.0}{5}{6:0.0}", "({0:0.0}{1}{2:0.0}){3}{4:0.0}{5}{6:0.0}", "{0:0.0}{1}({2:0.0}{3}{4:0.0}){5}{6:0.0}", "{0:0.0}{1}{2:0.0}{3}({4:0.0}{5}{6:0.0})", "({0:0.0}{1}{2:0.0}{3}{4:0.0}){5}{6:0.0}", "{0:0.0}{1}({2:0.0}{3}{4:0.0}{5}{6:0.0})" };
        char[] chArray = new char[] { '+', '-', '*', '/' };
        while (num-- > 0)
        {
            string[] strArray2 = Console.ReadLine().Split(new char[0]);
            double num2 = double.Parse(strArray2[0]);
            double num3 = double.Parse(strArray2[1]);
            double num4 = double.Parse(strArray2[2]);
            double num5 = double.Parse(strArray2[3]);
            bool flag = false;
            string expression = string.Empty;
            foreach (char ch in chArray)
            {
                foreach (char ch2 in chArray)
                {
                    foreach (char ch3 in chArray)
                    {
                        foreach (string str2 in strArray)
                        {
                            expression = string.Format(str2, new object[] { num2, ch, num3, ch2, num4, ch3, num5 });
                            try
                            {
                                if (Math.Abs((double) (double.Parse(table.Compute(expression, null).ToString()) - 24.0)) < 1E-06)
                                {
                                    flag = true;
                                    Debug.WriteLine(expression);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            Debug.WriteLine((string) null);
            if (flag)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
      

  4.   

    static void Main(string[] args)
            {
                List<string> answer = Compute24(9, 6, 7, 8);
     
                if (answer != null && answer.Count != 0)
                {
                    foreach (string item in answer)
                    {
                        Console.WriteLine(item);
                    }
                }
                else
                {
                    Console.WriteLine("No answer");
                }
                 Console.Read();
            }
     
            static List<string> Compute24(int a, int b, int c, int d)
            {
                List<string> finalResult = new List<string>();
                int[] arr = new int[4] { a, b, c, d };
     
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (j == i)
                        {
                            continue;
                        }
                        for (int k = 0; k < 4; k++)
                        {
                            if (k == i || k == j)
                            {
                                continue;
                            }
                            for (int l = 0; l < 4; l++)
                            {
                                if (l == i || l == j || l == k)
                                {
                                    continue;
                                }
                                List<string> result = ComputeWithArred(arr[i], arr[j], arr[k], arr[l]);
                                if (result != null && result.Count > 0)
                                {
                                    foreach (string item in result)
                                    {
                                        finalResult.Add(item);
                                    }
                                }
                            }
                        }
                    }
                }
                return finalResult;
            }
     
            static List<string> ComputeWithArred(int a, int b, int c, int d)
            {
                List<string> answer = new List<string>();
                char[] symbols = new char[4] { '+', '-', '*', '/' };
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            double ab = Compute(a, symbols[i], b);
                            double abc = Compute(ab, symbols[j], c);
                            double abcd = Compute(abc, symbols[k], d);
                            if ((abcd - 24 < 0.00000001) && (abcd - 24 > -0.00000001))
                            {
                                answer.Add("[(" + a + symbols[i] + b + ")" + symbols[j] + c + "]" + symbols[k] + d);
                            }
     
                            double cd = Compute(c, symbols[i], d);
                            double bcd = Compute(b, symbols[j], cd);
                            double Abcd = Compute(a, symbols[k], bcd);
                            if ((Abcd - 24 < 0.00000001) && (Abcd - 24 > -0.00000001))
                            {
                                answer.Add("" + a + symbols[k] + "[" + b + symbols[j] + "(" + c + symbols[i] + d + ")]");
                            }
                        }
                    }
                }
     
                return answer;
            }
     
            static double Compute(double a, char x, double b)
            {
                switch (x)
                {
                    case '+':
                        return a + b;
                    case '-':
                        return a - b;
                    case '*':
                        return a * b;
                    case '/':
                        return a / b;
                    default:
                        return 0;
                }
            }