static string GetValue(char c)
{
string chsValue = "零一二三四五六七八九";
string araValue = "0123456789";
return chsValue[araValue.IndexOf(c)].ToString();
}
static string GetUnit(int i)
{
string[] Unit = { "", "十", "百", "千", "萬", "十", "百", "千", "億", "十", "百", "千" };
return Unit[i];
}
static void Main(string[] args)
{
Console.Write(":");
char[] strNum = long.Parse(Console.ReadLine()).ToString().ToCharArray();
int high = strNum.Length - 1;
int plus = 0;
char zero = '0';
for (int i = high; i >= 0; i--)
{
if (plus == 4)
plus = 0;
if (zero == '0' && strNum[i] == '0')
strNum[i] = '-';
else
zero = strNum[i];
if (i < (i + plus) && i < (high - 3) && strNum[i] != '-' && strNum[i + plus] == '-')
strNum[i + plus] = '+';
if (plus == 1 && strNum[i] == '1' && i == 0)
strNum[i] = '+';
plus++;
}
if (strNum.Length == 1 && strNum[0] == '-')
strNum[0] = '0';
string chsNum = "";
int unit = 0;
for (int j = high; j >= 0; j--)
{
if (strNum[j] != '-')
{
if (strNum[j] == '+')
chsNum = GetUnit(unit) + chsNum;
else if (strNum[j] == '0')
chsNum = GetValue(strNum[j]) + chsNum;
else
chsNum = GetValue(strNum[j]) + GetUnit(unit) + chsNum;
}
unit++;
}
Console.WriteLine(chsNum);
Console.Read();
}
全站熱搜
留言列表