关闭

pat_BL_1019

标签: pat
60人阅读 评论(0) 收藏 举报
分类:

2016/8/31
输入范围0-9999
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))))
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:734次
    • 积分:190
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档