直接暴力:
1 #include <iostream> 2 #include <algorithm> 3 4 using namespace std; 5 6 int Fun(int * a, int n) { 7 int ans = 0; 8 for (int i = 0; i < n; i++) 9 ans = ans * 10 + a[i]; 10 return ans; 11 } 12 13 int main() 14 { 15 int arr[9] = { 1,2,3,4,5,6,7,8,9 }; 16 int a = 0, b = 0, c = 0; 17 do { 18 a = Fun(arr, 2); 19 b = Fun(arr + 2, 3); 20 c = Fun(arr + 5, 4); 21 if (c == a * b) 22 cout << a << " * " << b << " = " << c << endl; 23 } while (next_permutation(arr,arr + 9)); 24 return 0; 25 }
2021-04-30