问题描述:
这个算式中A~I代表1-9的数字,不同的字母代表不同的数字。
比如:
6+8/3+952/714 就是一种解法,
5+3/1+972/486 是另一种解法。
这个算式一共有多少种解法?
注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字
问题分析:
可以使用全排列的方法进行填空,直到找出符合条件的等式为止。
#include<bits/stdc++.h>
using namespace std;
int p[]={1,2,3,4,5,6,7,8,9};
int ans;
int main(){
do{
int a=p[0];
int b=p[1];
int c=p[2];
int def=p[3]*100+p[4]*10+p[5];
int ghi=p[6]*100+p[7]*10+p[8];
if(b*ghi+c*def==(10-a)*(ghi*c))
ans++;
}while(next_permutation(p,p+9));
cout<<ans<<endl;
return 0;
}
运行结果 :
最终可得结果为29