输入一个三位或四位整数n,求满足:xyz+yzz=n的所有x,y,z,如果没有对应的组合则输出"无对应组合"
时间: 2024-05-27 15:14:00 浏览: 147
n = input("请输入一个三位或四位整数:")
length = len(n)
if length == 3:
for x in range(1, 10):
for y in range(0, 10):
z = n - int(str(y) + str(y))
if 100 <= z < 1000 and str(z)[0] == str(x):
print(x, y, z)
break
else:
continue
break
else:
print("无对应组合")
elif length == 4:
for x in range(1, 10):
for y in range(0, 10):
z = n - int(str(y) + str(y) + str(x))
if 1000 <= z < 10000 and str(z)[1:] == str(y) + str(x):
print(x, y, z)
break
else:
continue
break
else:
print("无对应组合")
else:
print("请输入一个三位或四位整数")
阅读全文