问题描述
请看下面的算式:
(ABCD - EFGH) * XY = 900
每个字母代表一个 0 ~ 9 的数字,不同字母代表不同数字,首位不能为 0。
比如,(5012 - 4987) * 36 就是一个解。
请找到另一个解,并提交该解中 ABCD 所代表的整数。
答案提交
请严格按照格式,通过浏览器提交答案。
注意:只提交 ABCD 所代表的整数,不要写其它附加内容,比如:说明性的文字。
答案:6048
题解
全排列:
#include <iostream>
#include <algorithm>
using namespace std;
int s[10];
int main()
{
for (int i = 0; i < 10; i ++) s[i] = i;
do
{
if(s[0] != 0 && s[4] != 0 && s[8] != 0)
{
int a = s[0] * 1000 + s[1] * 100 + s[2] * 10 + s[3];
int b = s[4] * 1000 + s[5] * 100 + s[6] * 10 + s[7];
int c = s[8] * 10 + s[9];
if((a - b) * c == 900) cout << a << endl;
}
}while(next_permutation(s, s + 10));
return 0;
}