标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
while (true)
{
string s = Console.ReadLine();
if (s == "0")
{
break;
}
int n = s.Length;
StringBuilder str = new StringBuilder();
for (int i = 0; i < n; i++)
{
if (int.Parse(s[i].ToString()) == 0)
{
if (n < 9&&n-i==5)
{
str.Append("万");
}//亿以内万位为零特殊处理
else
{
if (!str.ToString().EndsWith("零"))
{
str.Append("零");
}
}
}
else
{
str.Append(ConvertZh(int.Parse(s[i].ToString())));
str.Append(GetWei(n - i));
}
}
if (str.ToString().EndsWith("零"))
{
str.Remove(str.Length-1, 1);
}
str.Replace("零万", "万");
Console.WriteLine(str);
}
Console.ReadLine();
;
}
private static string ConvertZh(int a)
{
switch (a)
{
case 1:
return "壹";
break;
case 2:
return "贰";
break;
case 3:
return "叁";
break;
case 4:
return "肆";
break;
case 5:
return "伍";
break;
case 6:
return "陆";
break;
case 7:
return "柒";
break;
case 8:
return "捌";
break;
case 9:
return "玖";
break;
}
return "";
}
private static string GetWei(int a)
{
switch (a)
{
case 2:
return "拾";
break;
case 3:
return "佰";
break;
case 4:
return "仟";
break;
case 5:
return "万";
break;
case 6:
return "拾";
break;
case 7:
return "佰";
break;
case 8:
return "仟";
break;
case 9:
return "亿";
break;
}
return "";
}
}
}
标签:
原文地址:http://www.cnblogs.com/cos0930/p/5420761.html