给定一个数,打印其中0~9各数出现的次数

POS_STEP = 1
NEG_STEP = -1

class _NumLen:
    def poinStatus(self, num, i):
        i = i - 1   #10的次方0时为1
        iEqu = num - (10** i) >= 0
        iSub = num - (10** (i - 1)) >= 0
        iAdd = num - (10** (i + 1)) >= 0

        print(iEqu, iSub, iAdd, 10** i)
        if iEqu and iSub and iAdd:
            return "less"
        if not iEqu and not iSub and not iAdd:
            return "over"
        if iEqu and iSub and not iAdd:
            return "reach"
    
    def seek(self, num):
        i = int()
        j = int()
        i = 1
        while True:
            print(i)
            status = self.poinStatus(num, i)
            if status == "less":
                i *= 2
            if status == "over":
                i /= 2
                i += i/2
                i = int(i)
            if status == "reach":
                return i
            
    def main(self, num):
        Len = int
        Len = self.seek(num)
        return Len
        

class _ListNumber:
    
    def end(self, i, posNeg):
        if posNeg < 0:
            return i - 1
        return i + 1
        
    def main(self, num):
        global POS_STEP
        global NEG_STEP
        
        List = list()    #长度为nuLen(num)
        i = int()
        temp = int()
        temp = 0

        for i in range(numLen(num), self.end(1, NEG_STEP), NEG_STEP):
            i -= 1
            List.append(int(num/(10** i)) - 10 * temp)
            temp = int(num/(10** i))
        return List

class _DictStatistics:
    
    def end(self, i, posNeg):
        if posNeg < 0:
            return i - 1
        return i + 1
    
    def genDict(self):
        global POS_STEP
        Dict = dict()
        for i in range(0, self.end(9, POS_STEP), POS_STEP):
            Dict[i] = 0
        return Dict
    
    def main(self, List):
        Dict = dict()
        Dict = self.genDict()
        for i in List:
            Dict[i] += 1
        return Dict

def numLen(num):
        _object = _NumLen()
        return _object.main(num)

def listNumber(num):
        _object = _ListNumber()
        return _object.main(num)
    
def dictStatistics(List):
        _object = _DictStatistics()
        return _object.main(List)
    

def main(num):
    global POS_STEP
    List = listNumber(num)
    print(List)
    Dict = dictStatistics(List)
    for i in range(0,9 + 1, POS_STEP):
        print(i , ":" ,Dict[i])

main(114514)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值