最近做的题里A的最感动的一道……我要哭了。
- 对0的处理,切成两半后连接点处的0,还有连续0的处理。
- 负数!
- 编码!
# a = '9999999'
m = str(a)
totalans = ''
if(m[0] == '-'):
m = m[1:]
totalans += u'负'
p = len(m)
dict1 = {'0':u'零','1':u'壹','2':u'贰','3':u'叁','4':u'肆','5':u'伍','6':u'陆','7':u'柒','8':u'捌','9':u'玖'}
dict2 = [u'拾',u'佰',u'仟','']
def four(s):
ans = ''
tlen = len(s)
for i in range(tlen):
# print(ans, i, tlen-1, s[i])
if(p != 1):
if(i == 0 and flag != 1 and s[i] != '0'):
if(m[3] == '0' and m[2] == '0'):
ans += u'零'
if(i == tlen-1 and s[i] == '0'): #像1000 10 100 尾0不加‘零’
continue;
if(s[i] == '0' and s[i+1] == '0'):#中间有多个连续的0只加一个0
continue;
ans += dict1[s[i]]
# print(ans, i, tlen-1, s[i])
if(p != 1):
if(s[i] == '0' and s[i+1] !='0'):
continue
ans += dict2[tlen-i-2]
return ans
if(p>4):
flag = 1
head = m[:p-4]
totalans += four(head)
totalans += u'万'
flag = 0
tail = m[p-4:]
totalans += four(tail)
else:
flag = 1
totalans += four(m)
totalans += u'圆'
print(totalans)