用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