2021-07-18

好像只有一个答案

给定等式:

 A B C D E
     D F G
+    D F G
____________
 X Y Z D E

其中每个字母代表不同的数字(0-9),编程求出这些数字,并打印等式。

for g in [0, 5]:
    for a in range(1, 10):
        for d in range(1, 10):
            for b in range(0, 10):
                for c in range(0, 10):
                    for e in range(0, 10):
                        for f in range(0, 10):
                            temp = [a, b, c, d, e, f, g]
                            temp = set(temp)
                            if len(temp) != 7:
                                continue
                            k = e + d * 10 + c * 100 + b * 1000 + a * 10000 + 2 * (g + f * 10 + d * 100)
                            result = []
                            mark = 0
                            for i in range(0, 5):
                                if i == 1 and k % 10 != d:
                                    mark = 1
                                    break
                                result.append(k % 10)
                                k = k // 10
                            if mark == 0 and k < 100000 and result[4] != 0:
                                temp = [a, b, c, d, e, f, g, result[4], result[3], result[2]]
                                temp = set(temp)
                                if len(temp) != 10:
                                    continue
                                print(" ", a, b, c, d, e)
                                print("     ", d, f, g)
                                print("+", "   ", d, f, g)
                                print("____________")
                                print(" ", result[4], result[3], result[2], result[1], result[0])
                                print()

  2 9 7 8 6
      8 5 0
+     8 5 0
____________
  3 1 4 8 6
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值