当前位置: 首页 > 工具软件 > CDE > 使用案例 >

ab*cde = adb*ce

夹谷星剑
2023-12-01

a、b、c、d、e是1~9的各不相同的五个数,满足条件ab * cde = adb * ce共有多少种。
例:14 * 253 = 3542
154 * 23 = 3542
首先,a、b、c、d、e均为1~9,可判断用循环,循环次数为九
其次:五个数各不相同,ab可以为68 ,也可以是86,但不能是66
方法一:

			int temp = 0;//计数器
			//五个数均为1~9,用五个循环即可
            for (int a = 1; a <= 9; a++)
            {
                for (int b = 1; b <= 9; b++)
                {
                    for (int c = 1; c <= 9; c++)
                    {
                        for (int d = 1; d <= 9; d++)
                        {
                            for (int e = 1; e <= 9; e++)
                            {
                            //进行条件判断,五个数各不相同
                                if ((a != b & a != c & a != d & a != e) & (b != c & b != d & b != e) & (c != d & c != e) & d != e)
                                {
                                    int ab = (a * 10) + b;
                                    int cde = (c * 100) + (d * 10) + e;
                                    int adb = (a * 100) + (d * 10) + b;
                                    int ce = (c * 10) + e;
                                    //嵌套if,在满足五个数各不相同的条件下进行判断
                                    if( ab * cde == adb * ce)
                                    {
                                        System.Console.WriteLine(ab + " * " + cde + " = "+ adb + " * " + ce + " = " + adb * ce );
                                        temp++;//满足条件计数器自增
                                    }
                                }
                            }
                        }
                    }

                }
            }
            System.Console.WriteLine("组数: " + temp);

方法二:(此处未完善)

			int temp = 0;//计数器
			//五个数均为1~9,用五个循环即可
            for (int a = 1; a <= 9; a++)
            {
                for (int b = 1; b <= 9; b++)
                {
                if(a == b)//如果a = b,跳出循环
                continue;
                    for (int c = 1; c <= 9; c++)
                    {
                    //经过上面的循环,此处a 必定不等于b,以此类推
                    if(b == c)//如果b = c,跳出循环
                continue;
                        for (int d = 1; d <= 9; d++)
                        {
                            for (int e = 1; e <= 9; e++)
                            {
                            //进行条件判断,五个数各不相同
                            //之后自行完善即可
                                if ()
                                {
                                    int ab = (a * 10) + b;
                                    int cde = (c * 100) + (d * 10) + e;
                                    int adb = (a * 100) + (d * 10) + b;
                                    int ce = (c * 10) + e;
                                    //嵌套if,在满足五个数各不相同的条件下进行判断
                                    if( ab * cde == adb * ce)
                                    {
                                        System.Console.WriteLine(ab + " * " + cde + " = "+ adb + " * " + ce + " = " + adb * ce );
                                        temp++;//满足条件计数器自增
                                    }
                                }
                            }
                        }
                    }

                }
            }
            System.Console.WriteLine("组数: " + temp);

好了,方法一已经是完整的代码了,方法二是在一的基础上改进,只不过是判断五个数各不相同的位置拆分出来了,自行思考即可

 类似资料: