5 条题解

  • 1
    @ 2024-9-26 22:17:14
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int x1, y1, x2, y2;
    int sum;
    
    int main()
    {
        int arr[9] = {1,2,3,4,5,6,7,8,9};
        while(next_permutation(arr, arr+9))
        {
            sum = 1000*arr[0] + 100*arr[1] + 10*arr[2] + arr[3];
            x1 = arr[4];
            y1 = 1000*arr[5] + 100*arr[6] + 10*arr[7] + arr[8];//第一种组合情况
            
            x2 = 10*arr[4] + arr[5];
            y2 = 100*arr[6] + 10*arr[7] + arr[8];//第二种组合情况
    
            if(sum == x1*y1)
            {
                cout << sum << " = "<< x1 << " x " << y1 << endl;
            }
            else if(sum == x2*y2)
            {
                cout << sum << " = "<< x2 << " x " << y2 << endl;
            }
    
        }
    
       
        return 0;
    }
    

    信息

    ID
    4
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    16
    已通过
    7
    上传者