zoukankan      html  css  js  c++  java
  • 小学三年级数学题!用数字 1 到 8 组成两个三位数使其和为 1000

    用数字 1 到 8 组成两个三位数使其和为 1000,这两个三位数里面的数字不能重复。

    问能写几组?

    用小学三年级的解题思路还真没想到。

    只好用笨方法跑个小程序了。

    L=list(range(1,9))
    #print(L)
    
    s=""
    S=[]
    for l in L:
        for l1 in L:
            for l2 in L:
                if str(l)<>str(l1) and str(l)<>str(l2) and str(l1)<>str(l2):
                    s=str(l) + str(l1) + str(l2)
                    S.append(s)
    
    
    def IsSame(a,b):
        v=True
        for al in a:
            for bl in b:
                if al==bl:
                    v= False
        return v
    
    
    C1000=[]
    for c in S:
        v=1000-int(c)
        if str(v)[0]<>str(v)[1] and str(v)[0]<>str(v)[2] and str(v)[1]<>str(v)[2] and str(v)[2]<>'9' and IsSame(c,str(v)):
            C1000.append(c)
    
    #print(C1000)
    #print(len(C1000))
    
    n=1
    DisplayList=[]
    for i in range(len(C1000)/2):
        DisplayList.append(C1000[i] + " + " + C1000[len(C1000)-n] + " = 1000")
        n+=1
    
    print(DisplayList)


    最终结果有 24 组:

    '124 + 876 = 1000', '126 + 874 = 1000', 
    '143 + 857 = 1000', '147 + 853 = 1000', 
    '153 + 847 = 1000', '157 + 843 = 1000', 
    '174 + 826 = 1000', '176 + 824 = 1000', 
    '214 + 786 = 1000', '216 + 784 = 1000', 
    '284 + 716 = 1000', '286 + 714 = 1000',
    '342 + 658 = 1000', '348 + 652 = 1000', 
    '352 + 648 = 1000', '358 + 642 = 1000', 
    '413 + 587 = 1000', '417 + 583 = 1000',
    '432 + 568 = 1000', '438 + 562 = 1000', 
    '462 + 538 = 1000', '468 + 532 = 1000', 
    '483 + 517 = 1000', '487 + 513 = 1000'
  • 相关阅读:
    Python 循环语句
    Python if、elif 、else语句 与 布尔运算
    Python 运算符
    Python 标识符
    Python 常用数据类型(整数,浮点数,复数,布尔型)
    Python 编辑器内容
    Python 语言介绍
    vscode 最新中文设置
    漫画数据库_基础和设计数据库
    linux配置服务器
  • 原文地址:https://www.cnblogs.com/Cein/p/7642560.html
Copyright © 2011-2022 走看看