给出把中文大写转换为阿拉伯数字程序
时间: 2024-05-09 11:20:48 浏览: 139
这是一个将中文大写转换为阿拉伯数字的Python程序:
```python
def chinese_to_arabic(chinese_str):
digits = {
'零': 0,
'一': 1,
'二': 2,
'三': 3,
'四': 4,
'五': 5,
'六': 6,
'七': 7,
'八': 8,
'九': 9
}
units = {
'十': 10,
'百': 100,
'千': 1000,
'万': 10000,
'亿': 100000000
}
total = 0
r = 1 # 表示单位
for i in range(len(chinese_str)-1, -1, -1):
val = digits.get(chinese_str[i])
if val is None:
unit = units.get(chinese_str[i])
if unit:
if unit >= 10000:
total += r * total
total *= unit
r = 1
else:
r = unit
else:
if r != 1:
val *= r
r = 1
total += val*r
if r != 1:
total *= r
return total
print(chinese_to_arabic("一千零一"))
```
输出:
```
1001
```
阅读全文