重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
前些天朋友公司的考试题,他们跟我说了,我没事做了做。简单的实现了一下。里面有的英文单词不对,不想改了,呵呵,反正就是这个意思。代码写的有点冗余,但功能还是实现了。不过只做了四位数的。
成都创新互联公司主打移动网站、网站设计、网站制作、网站改版、网络推广、网站维护、域名注册、等互联网信息服务,为各行业提供服务。在技术实力的保障下,我们为客户承诺稳定,放心的服务,根据网站的内容与功能再决定采用什么样的设计。最后,要实现符合网站需求的内容、功能与设计,我们还会规划稳定安全的技术方案做保障。
namespace CountNum
{
class Program
{
static void Main(string[] args)
{
Dictionary
Dictionary
Dictionary
//读取数字文本
string[] textNums = File.ReadAllLines("1.txt", Encoding.UTF8);
string[] saveTestEnglish = new string[textNums.Length];
for (int i = 0; i < textNums.Length; i++)
{
Match match = Regex.Match(textNums[i], @"\d[1-9]");
//int number = int.Parse(textNums[i]);
string number = textNums[i];
if (match.Success)
{
switch (number.Length)
{
case 1:
//个位数的英文读入
int ge = int.Parse(number);
saveTestEnglish[i] = dicGeEnglishGeWei[ge];
break;
case 2:
if (number[0] == '1')
{
int shi = int.Parse(number);
saveTestEnglish[i] = dicGetDuble[shi];
}
else
{
saveTestEnglish[i] = dicGetEnglishShiWei[SubS(number)] + dicGeEnglishGeWei[SubS((int.Parse(number) - 1).ToString())];
}
break;
case 3:
if (number[1] == '1')
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " hunred and" + dicGetDuble[int.Parse(number.Substring(1))];
}
else
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " hunred and" + dicGetEnglishShiWei[SubS(number.Substring(1))] + dicGeEnglishGeWei[SubS(number.Substring(2))];
}
break;
case 4:
if (number[2] == '1')
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " thousand " + dicGeEnglishGeWei[SubS(number.Substring(1))] + " hunred and" + dicGetDuble[int.Parse(number.Substring(2))];
}
else
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " thousand " + dicGeEnglishGeWei[SubS(number.Substring(1))] + " hunred and" + dicGetEnglishShiWei[SubS(number.Substring(2))] + dicGeEnglishGeWei[SubS(number.Substring(3))];
}
break;
default:
break;
}
}
else
{
saveTestEnglish[i] = "Error";
}
}
for (int j = 0; j < saveTestEnglish.Length; j++)
{
Console.WriteLine(saveTestEnglish[j]);
}
Console.Read();
}
///
/// 截取位数上的数
///
///
///
static int SubS(string num)
{
int danwei = 0;
danwei = int.Parse(num.Substring(0, 1));
return danwei;
}
///
///返回个位数字对应的英文
///
///
static Dictionary
{
#region 个位数字典
Dictionary
dicSingle.Add(1, " one");
dicSingle.Add(2, " two");
dicSingle.Add(3, " three");
dicSingle.Add(4, " four");
dicSingle.Add(5, " five");
dicSingle.Add(6, " six");
dicSingle.Add(7, " seven");
dicSingle.Add(8, " eight");
dicSingle.Add(9, " ine");
dicSingle.Add(0, "");
#endregion
return dicSingle;
}
static Dictionary
{
#region 个位数字典
Dictionary
dicSingle.Add(1, " ten");
dicSingle.Add(2, " twenty");
dicSingle.Add(3, " thirty");
dicSingle.Add(4, " forty");
dicSingle.Add(5, " fifty");
dicSingle.Add(6, " sixty");
dicSingle.Add(7, " seventy");
dicSingle.Add(8, " eighty");
dicSingle.Add(9, " ninty");
dicSingle.Add(0, "");
#endregion
return dicSingle;
}
static Dictionary
{
#region 个位数字典
Dictionary
dicSingle.Add(10, " ten");
dicSingle.Add(11, " eleven");
dicSingle.Add(13, " thirsteen");
dicSingle.Add(14, " fourteen");
dicSingle.Add(15, " fifteen");
dicSingle.Add(16, " sixteen");
dicSingle.Add(17, " seventeen");
dicSingle.Add(18, " eighteen");
dicSingle.Add(19, " nineteen");
dicSingle.Add(12, " twelve");
#endregion
return dicSingle;
}
}
}