【问题描述】
小明的作业本上有道思考题: 看下面的算式: (□□□□-□□□□)*□□=900
其中的小方块代表 0 ~ 9 的数字,这10个方块刚好包含了0~9中的所有数字。 注意:0不能作为某个数字的首位。
小明经过几天的努力,终于做出了答案!如下: (5012-4987)*36=900
用计算机搜索后,发现还有另外一个解,本题的任务就是:请你算出这另外的一个解。
【答案提交】
注意:提交的格式需要与示例严格一致;括号及运算符号不要用中文输入法;
整个算式中不能包含空格。不要填写任何多余的内容,比如说明文字。
暴力:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
for (int a = 1; a <= 9; a ++)
for (int b = 0; b <= 9; b ++)
for (int c = 0; c <= 9; c ++)
for (int d = 0; d <= 9; d ++)
for (int e = 1; e <= 9; e ++)
for (int f = 0; f <= 9; f ++)
for (int g = 0; g <= 9; g ++)
for (int h = 0; h <= 9; h ++)
for (int i = 1; i <= 9; i ++)
for (int j = 0; j <= 9; j ++)
{
if(a != b && a != c && a != d && a != e && a != f && a != g && a != h && a != i && a != j
&& b != c && b != d && b != e && b != f && b != g && b != h && b != i && b != j
&& c != d && c != e && c != f && c != g && c != h && c != i && c != j
&& d != e && d != f && d != g && d != h && d != i && d != j
&& e != f && e != g && e != h && e != i && e != j
&& f != g && f != h && f != i && f != j
&& g != h && g != i && g != j
&& h != i && h != j
&& i != j
&& (a*1000 + b*100 + c*10 + d - e*1000 - f*100 - g*10 - h) * (i*10 + j) == 900)
printf("(%d%d%d%d-%d%d%d%d)*%d%d\n", a, b, c, d, e, f, g, h, i, j);
}
return 0;
}
答案:(6048-5973)*12 (程序要跑30多秒 o(╥﹏╥)o)
如果感觉这篇文章对你有帮助的话,不妨点一个赞,十分感谢(✪ω✪)。
printf(“点个赞吧!”);
cout <<“点个赞吧!”;
System.out.println(“点个赞吧!”);
↓↓↓