#!/usr/bin/python # coding:utf-8 import time num = [u'零', u'一', u'二', u'三', u'四', u'五', u'六', u'七', u'八', u'九'] kin = [u'十', u'百', u'千', u'万', u'零'] def sadd(x): x.reverse() if len(x) >= 2: x.insert(1, kin[0]) if len(x) >= 4: x.insert(3, kin[1]) if len(x) >= 6: x.insert(5, kin[2]) if len(x) >= 8: x.insert(7, kin[3]) if len(x) >= 10: x.insert(9, kin[0]) if len(x) >= 12: x.insert(11, kin[1]) if len(x) >= 14: x.insert(13, kin[2]) x = fw(x) x = d1(x) x = d2(x) x = dl(x) return x def rankis(): rank = [] for i in range(99999999): i = list(str(i)) for j in i: i[(i.index(j))] = num[int(j)] i = sadd(i) rank.append(i) return rank def d1(x): if u'零' in x: a = x.index(u'零') if a == 0: del x[0] d1(x) else: if x[a + 2] in [u'十', u'百', u'千', u'万', u'零']: if x[a + 1] != u'万': del x[a + 1] d1(x) return x def d2(x): try: a = x.index(u'零') if x[a - 1] in [u'十', u'百', u'千', u'零']: del x[a - 1] d2(x[a + 1]) except: pass return x def fw(x): if len(x) >= 9: if x[8] == u'零': del x[8] return x def dl(x): try: if x[0] == u'零': del x[0] except: pass x.reverse() x = ''.join(x) return x def digit2Chinese(i): if i >= 100000000: #print('Do not support number over 99999999...') return '' i = list(str(i)) for j in i: i[(i.index(j))] = num[int(j)] return sadd(i) if __name__ == '__main__': start = time.time() # rank = rankis() end = time.time() - start print('程序共用时:%0.2f' % end)