2025年5月23日 星期五

中文數字

 r = '零一二三四五六七八九'

a = ['萬','千','百','十','萬','千','百','十','']

rn = '0123456789'


n = int(input())

d = [r[rn.find(str(i))] for i in str(n)]

d = ''.join(d)


s = ''

i,k = len(d)-1,len(a)-1 

while i>=0:

s =  d[i] + a[k] + s

i = i -1

k = k - 1


s = s.replace('零十','零')

s = s.replace('零百','零')

s = s.replace('零千','零')

s = s.replace('零萬','零')

while s.find('零零')>0:s = s.replace('零零','零')

if s=='零':

print(s,end='')

elif s[-1]=='零':

print(s[:-1],end='')

else:

print(s,end='')

沒有留言:

張貼留言