Divide the 9 numbers 1, 2, ..., 9 into 3 groups to form 3 three-digit numbers respectively, and make these three three-digit numbers form a ratio of 1:2:3, and try to find all those that meet the conditions Three three-digit numbers.

 This is cumbersome to write...

using System;



namespace ConsoleApp1

{

    class Program

    {

        static void Main(string[] args)

        {

           

            int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            bool[] vis = new bool[20]; 

            for(int i = 0; i < 9; i++){

                for(int j = 0; j < 9; j++){

                    if (j == i) continue;

                    for(int k = 0; k < 9; k++){

                        if (k == j || k == i) continue;

                        for (int f = 0; f <= 9; f++){

                            vis[f] = false;

                        }



                        vis[a[i]] = vis[a[j]] = vis[a[k]] = true;



                        int num1 = a[i] * 100 + a[j] * 10 + a[k];



                        int num2 = num1 * 2;

                        int[] b = new int[3];

                        int tot2 = 0;

                        if (num2 > 999) continue;



                        while (num2 > 0){

                            b[tot2++] = num2 % 10;

                            num2 /= 10;

                        }

                        Array.Reverse(b);



                        int[] c = new int[3];

                        int num3 = num1 * 3;

                        int tot3 = 0;

                        if (num3 > 999) continue;

                        while (num3 > 0){

                            c[tot3++] = num3 % 10;

                            num3 /= 10;

                        }

                        Array.Reverse(c);



                        bool flag1 = false;

                        bool flag2 = false;

                        if (b[0]==0||b[1]==0||b[1]==0||b[0] == b[1] || b[0] == b[2] || b[1] == b[2]) continue;



                        if (vis[b[0]] == false && vis[b[1]] == false && vis[b[2]] == false) {



                            flag1 = true;

                            vis[b[0]] = true; vis[b[1]] = true; vis[b[2]] = true;

                        }



                        if (c[0]==0||c[1]==0||c[2]==0||c[0] == c[1] || c[0] == c[2] || c[1] == c[2]) continue;



                        if (vis[c[0]]==false && vis[c[1]] == false && vis[c[2]] == false) {

                            flag2 = true;

                            vis[c[0]] = true; vis[c[1]] = true; vis[c[2]] = true;

                        }



                        if (flag1 == true && flag2 == true) {

                            Console.Write(num1);Console.Write(" ");

                            Console.Write(num1 * 2);Console.Write(" ");

                            Console.WriteLine(num1 * 3);

                        }



                    }

                }

            }

        }

    }

}


    {

        static void Main(string[] args)

        {

            int[] num = new int[10];

            for(int a = 123; a < 333; a++)

            {

                int b = 2 * a;

                int c = 3 * a;
         

                num[0] = a / 100 % 10; num[1] = a / 10 % 10; num[2] = a % 10;

                num[3] = b / 100 % 10; num[4] = b / 10 % 10; num[5] = b % 10;

                num[6] = c / 100 % 10; num[7] = c / 10 % 10; num[8] = c % 10;

                

                if(num.Contains(1) && num.Contains(2) && num.Contains(3) && num.Contains(4) && num.Contains(5) && num.Contains(6) && num.Contains(7) && num.Contains(8) && num.Contains(9))

                {

                    Console.WriteLine(a.ToString() + "  " + b.ToString() + "  " + c.ToString());

                }

            }

        }

    }

 

Guess you like

Origin blog.csdn.net/zstuyyyyccccbbbb/article/details/115091749