using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DesignPatterns.ChineseNumConvertor
{
public class Node
{
public string Unit { get; set; }
public string Num { get; set; }
public Node Left { get; set; }
public Node Right { get; set; }
public long CalcVal()
{
return ((Left != null ? Left.CalcVal() : 0) + CNConvertor.numMapping[this.Num]) * CNConvertor.unitMapping[this.Unit] +
(this.Right != null ? this.Right.CalcVal() : 0);
}
}
public class CNConvertor
{
public static string[] units = new string[] { "亿", "万", "千", "百", "十" };
public static string[] numbers = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九" };
public static Dictionary<string, int> unitMapping = new Dictionary<string, int>()
{
{ "亿", 100000000 },
{ "万", 10000 },
{ "千", 1000 },
{ "百", 100 },
{ "十", 10 },
{ "一", 1 }
};
public static Dictionary<string, int> numMapping = new Dictionary<string, int>()
{
{ "一", 1 },
{ "二", 2 },
{ "三", 3 },
{ "四", 4 },
{ "五", 5 },
{ "六", 6 },
{ "七", 7 },
{ "八", 8 },
{ "九", 9 },
{ "零", 0 }
};
public static Dictionary<int, string> numMappi
c# - 汉字数字,阿拉伯数字,相互转换
最新推荐文章于 2021-04-20 20:25:36 发布
本文介绍如何在C#中实现汉字数字与阿拉伯数字之间的转换。内容涵盖转换的算法和示例代码,帮助开发者在处理数字字符串时进行有效转换。
摘要由CSDN通过智能技术生成