运算符穷举

namespace 运算符穷举
{
    class Program
    {
        static void Main(string[] args)
        {   //123()45()68=100; 在括号里面添加+ -使等式成立 
            int a; int b; 
            for (int i = 0; i < 2; i++)    //有0 和1 两种可能, 0代表加法,1代表减法
            {
                for (int j = 0; j < 2; j++)
                {
                    if (i == 0)
                    {
                         a = 1;
                    }
                    else
                    {
                         a = -1;
                    }
                    if (j == 0)
                    {
                         b = 1;
                    }
                    else
                    {
                        b = -1;
                    }
                    if(123+a*45+b*68==100)  //定义的a b 是为了输出加法的运算符  当a=1为加法,a=-1为减法,b也一样
                    {
                    if(a==1)
                    {
                        Console.Write("第一格为加法,");
                    }
                    else
                    {
                        Console.Write("第一格为减法,");
                    }
                    if (b== 1)
                    {
                        Console.WriteLine("第二格为加法");
                    }
                    else
                    {
                        Console.WriteLine("第二格为减法");
                    }
                    }
                }
            }
            Console.ReadLine();
        }
    }
}

posted @ 2015-04-15 22:46  XCml  阅读(135)  评论(0编辑  收藏  举报