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~9各数出现的次数
最新推荐文章于 2024-09-07 22:54:47 发布