C语言编程实现,输入一个人民币小写金额值(不考虑角和分),转化为大写金额值输出。先实现基本功能,如输

编程实现,输入一个人民币小写金额值(不考虑角和分),转化为大写金额值输出。先实现基本功能,如输入1002300,可以输出“壹佰零拾零万贰仟叁佰零拾零元”。(提示:首先分离... 编程实现,输入一个人民币小写金额值(不考虑角和分),转化为大写金额值输出。先实现基本功能,如输入1002300,可以输出“壹佰零拾零万贰仟叁佰零拾零元”。(提示:首先分离出来每一位数字,并存入到一个数组中。然后将数组中的每一位数转化为大写形式,并加上适当的单位。) 展开
 我来答
百度网友aaff635
2011-06-13 · 超过13用户采纳过TA的回答
知道答主
回答量:115
采纳率:0%
帮助的人:41.3万
展开全部
c#的代码,包括角和分的情况
class Program
{
static void Main(string[] args)
{
Console.WriteLine("input money (输入仟亿元以内):");
string money = Console.ReadLine();
string[] fenkai = money.Split('.');//按.分成两部分
string[] zhengshu=new string[fenge(fenkai[0],4).Length];
for (int i = 0; i < zhengshu.Length; i++)
{
zhengshu[i] = fenge(fenkai[0], 4)[i];
} //整数按4分割存入整数数组
string s=null;
int b = zhengshu.Length;

if (b == 4) //万亿以内
{
int a = zhengshu[0].Length;
if (a == 1)
s = s + yiwei(zhengshu[0]) + "万亿";
else
if (a == 2)
s = s + liangwei(zhengshu[0]) + "万亿";
else
if (a == 3)
s = s + sanwei(zhengshu[0]) + "万亿";
else
if (a == 4)
s = s + siwei(zhengshu[0]) + "万亿";
else
Console.WriteLine("error");

s = s + siwei(zhengshu[1]) + "亿" + siwei(zhengshu[2]) + "万" + siwei(zhengshu[3]);

s = s + jiaofen(fenkai[1]);
}
else
if (b == 3) //千亿以内
{
int a = zhengshu[0].Length;
if (a == 1)
s = s + yiwei(zhengshu[0]) + "亿";
else
if (a == 2)
s = s + liangwei(zhengshu[0]) + "亿";
else
if (a == 3)
s = s + sanwei(zhengshu[0]) + "亿";
else
if (a == 4)
s = s + siwei(zhengshu[0]) + "亿";
else
Console.WriteLine("error");

s = s + siwei(zhengshu[1]) + "万" + siwei(zhengshu[2]);

s = s + jiaofen(fenkai[1]);

}
else
if (b == 2) //千万以内
{
int a = zhengshu[0].Length;
if (a == 1)
s = s + yiwei(zhengshu[0]) + "万";
else
if (a == 2)
s = s + liangwei(zhengshu[0]) + "万";
else
if (a == 3)
s = s + sanwei(zhengshu[0]) + "万";
else
if (a == 4)
s = s + siwei(zhengshu[0]) + "万";
else
Console.WriteLine("error");

s = s + siwei(zhengshu[1]);

s = s + jiaofen(fenkai[1]);

}
else
if (b == 1)
{
int a = zhengshu[0].Length;
if (a == 1)
s = s + yiwei(zhengshu[0]);
else
if (a == 2)
s = s + liangwei(zhengshu[0]);
else
if (a == 3)
s = s + sanwei(zhengshu[0]);
else
if (a == 4)
s = s + siwei(zhengshu[0]);
else
Console.WriteLine("error");

s = s + jiaofen(fenkai[1]);

}
else
Console.WriteLine("错误");
Console.WriteLine(s);

}

static string[] fenge(string str, int n) //分割字符从后往前n个分割,返回为字符数组,数组存的是按n位分割人结果
{
int qishi = str.Length % n;
int geshu = str.Length / n;
string[] baocun;

if (qishi == 0)
{
baocun = new string[geshu];
}
else
{
baocun = new string[geshu + 1];
}
;

if (qishi == 0) //整除
{
int i = 0;
for (int j = 0; j < geshu; j++)
{
baocun[j] = str.Substring(i, n);
i = i + 4;
}

}
else //没有整除
{
int i = qishi;
baocun[0] = str.Substring(0, qishi);
for (int j = 1; j < geshu + 1; j++)
{
baocun[j] = str.Substring(i, n);
i = i + 4;

}

}
return baocun;

}

static string hanzi(string str) //将阿拉伯转化汉字
{

string s = null;
switch (str)
{
case "0":
s = "零";
break;
case "1":
s = "壹";
break;
case "2":
s = "贰";
break;
case "3":
s = "叁";
break;
case "4":
s = "肆";
break;
case "5":
s = "伍";
break;
case "6":
s = "陆";
break;
case "7":
s = "柒";
break;
case "8":
s = "捌";
break;
case "9":
s = "玖";
break;
default:
Console.WriteLine("错误");
break;
}
return s;
}

static string siwei(string str)
{
string s = null;
string[] sshuzu = new string[str.Length];

for (int i = 0; i < str.Length; i++)
{
sshuzu[i] = str.Substring(i, 1);
}

if (sshuzu[0] == "0")
{
if (sshuzu[1] != "0" || sshuzu[2] != "0" || sshuzu[3] != "0")
s = hanzi(sshuzu[0]);
else
s = s + null;
}
else
s = s + hanzi(sshuzu[0]) + "仟";

if (sshuzu[1] == "0")
{
if (sshuzu[2] != "0" || sshuzu[3] != "0")
if (sshuzu[0] == "0")
s = s + null;
else
s = s + hanzi(sshuzu[1]);
else
s = s + null;
}
else
s = s + hanzi(sshuzu[1]) + "佰";

if (sshuzu[2] == "0")
{
if ( sshuzu[3] != "0")
if (sshuzu[1] == "0")
s = s + null;
else
s = s + hanzi(sshuzu[1]);
else
s = s + null;
}
else
s = s + hanzi(sshuzu[2]) + "拾";

if (sshuzu[3] == "0")
{
s = s + null;
}
else
s = s + hanzi(sshuzu[3]);
return s;

} //整数部分四位读法

static string sanwei(string str)
{
string s = null;
string[] sshuzu = new string[str.Length];

for (int i = 0; i < str.Length; i++)
{
sshuzu[i] = str.Substring(i, 1);
}

s = s + hanzi(sshuzu[0]) + "佰";

if (sshuzu[1] == "0")
if (sshuzu[2] == "0")
s = s + null;
else
s = s + hanzi(sshuzu[1]);
else
s = s + hanzi(sshuzu[1]) + "拾";

if (sshuzu[2] == "0")
s = s + null;
else
s = s + hanzi(sshuzu[2]);
return s;

} //整数部分三位读法

static string liangwei(string str)
{
string s = null;
string[] sshuzu = new string[str.Length];

for (int i = 0; i < str.Length; i++)
{
sshuzu[i] = str.Substring(i, 1);
}
s = s + hanzi(sshuzu[0]) + "拾";
if (sshuzu[1] == "0")
{
s = s + null;
}
else
s = s + hanzi(sshuzu[1]);
return s;

} //整数部分两位

static string yiwei(string str)
{
string s = null;
string[] sshuzu = new string[str.Length];

for (int i = 0; i < str.Length; i++)
{
sshuzu[i] = str.Substring(i, 1);
}
s = s + hanzi(sshuzu[0]);
return s;

} //整数部分一位

static string jiaofen(string str)
{
string s = null;
string[] sshuzu = new string[str.Length];

for (int i = 0; i < str.Length; i++)
{
sshuzu[i] = str.Substring(i, 1);
}
if (sshuzu[0] == "0" && sshuzu[1] == "0")
s = "元整";
else
if (sshuzu[0] != "0" && sshuzu[1] == "0")
s = "元"+s + hanzi(sshuzu[0]) + "角";
else
if (sshuzu[0] == "0" && sshuzu[1] != "0")
s ="元"+ s + hanzi(sshuzu[1]) + "分";
else
if (sshuzu[0] != "0" && sshuzu[1] != "0")

s = "元" + s + hanzi(sshuzu[0]) + "角" + hanzi(sshuzu[1]) + "分";
else
Console.WriteLine("error");

return s;

} //角分
}

input money (输入仟亿元以内):
1231231345.12
壹拾贰亿叁仟壹佰贰拾叁万壹仟叁佰肆拾伍元壹角贰分
Press any key to continue . . .
干吗寻找周杰伦
2011-06-13 · TA获得超过1805个赞
知道小有建树答主
回答量:1949
采纳率:0%
帮助的人:687万
展开全部
壹佰零拾零万贰仟叁佰零拾零元
这是哪国话?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式