1、注意结果不足四位要补0,否则运行超时。
2、第六个测试点5输入为6174,要至少输出一轮。
3、第345个测试点234输入不足4位,要补0。
if __name__ == '__main__':
number = "%04d" % int(input())
isEqual = True
n = [int(number[0])]
for i in range(1, len(number)):
if int(number[i]) not in n:
isEqual = False
n.append(int(number[i]))
if isEqual:
print("%s - %s = 0000" % (number, number))
else:
res = ""
while res != "6174":
maxNumber = ""
minNumber = ""
n.sort(reverse=True)
for i in n:
maxNumber += str(i)
n.sort(reverse=False)
for i in n:
minNumber += str(i)
res = "%04d" % (int(maxNumber) - int(minNumber))
print("%s - %s = %s" % (maxNumber, minNumber, res))
n = []
for i in res:
n.append(int(i))