实列

"""题目:有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去掉不满足条件的排列。"""
# 两种实现方法

for i in range(1, 433):
    i = str(i)
    if len(i) == 3:
        if i[1] not in ['0', '5', '6', '7', '8', '9'] and i[2] not in ['0', '5', '6', '7', '8', '9']:
            if i[0] not in i[1] and i[0] not in i[2] and i[1] not in i[2]:
                print(i)


for a in range(1, 5):
    for b in range(1, 5):
        for c in range(1, 5):
            if a != b and a != c and b != c:
                print(a, b, c)

猜你喜欢

转载自www.cnblogs.com/mrstephen/p/8984316.html