pat_BL_1019

2016/8/31

ac code

# -*- coding: utf-8 -*-
"""
Created on Tue Aug 30 21:35:34 2016

@author: hanzy
"""

def getnum(num):
big = sorted(num,reverse = True)
small = sorted(num)
bignumber = 1000*int(big[0])+100*int(big[1])+10*int(big[2])+int(big[3])
smallnumber = 1000*int(small[0])+100*int(small[1])+10*int(small[2])+int(small[3])
return bignumber,smallnumber
if __name__ == "__main__":
info = raw_input()
flag = 0
info = str('%04d'%int(info))
num = (int(info[0]),int(info[1]),int(info[2]),int(info[3]))
big = sorted(num,reverse = True)
small = sorted(num)
bignumber = 1000*int(big[0])+100*int(big[1])+10*int(big[2])+int(big[3])
smallnumber = 1000*int(small[0])+100*int(small[1])+10*int(small[2])+int(small[3])
if bignumber == smallnumber:
print str('%04d'%bignumber) + " - " + str('%04d'%bignumber) + " = 0000"
else:
while(flag != 1):
if int(bignumber) - int(smallnumber) == 6174:
flag = 1
print str('%04d'%bignumber) + " - " + str('%04d'%smallnumber) + " = " + str('%04d'%(int(bignumber)-int(smallnumber)))
bignumber,smallnumber = getnum(str('%04d'%(int(bignumber)-int(smallnumber))))
• 本文已收录于以下专栏：

举报原因： 您举报文章：pat_BL_1019 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)