用1、2、3、4、5、6、7、8、9這9 個數字填入等式使等式成立


 

直接暴力:

 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM