币值转换
输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式。如23108元,转换后变成“贰万叁仟壹百零捌”元。为了简化输出,用小写英文字母a-j顺序代表大写数字0-9,用S、B、Q、W、Y分别代表拾、百、仟、万、亿。于是23108元应被转换输出为“cWdQbBai”元。
输入格式:
输入在一行中给出一个不超过9位的非负整数。
输出格式:
在一行中输出转换后的结果。注意“零”的用法必须符合中文习惯。
输入样例1:
813227345
输出样例1:
iYbQdBcScWhQdBeSf
输入样例2:
6900
输出样例2:
gQjB
1)实验代码
#include <stdio.h>
char theValue[10] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
char theUnit[5] = { 'S','B','Q','W','Y' };
int Billion = 100000000;
char theUnit[5] = { 'S','B','Q','W','Y' };
int Billion = 100000000;
int main()
{
int num;
scanf("%d", &num);
{
int num;
scanf("%d", &num);
if (num == 0)
printf("a");
else
{
while (num)
{
if (num / Billion > 0)
break;
else
Billion /= 10;
}
printf("a");
else
{
while (num)
{
if (num / Billion > 0)
break;
else
Billion /= 10;
}
while (num)
{
int temp = num / Billion;
{
int temp = num / Billion;
if (temp == 0)
{
if ((num - temp * Billion) / (Billion / 10) != 0)
printf("a");
}
else
{
printf("%c", theValue[temp]);
if (Billion == 1e5 || Billion == 1e1)
printf("%c", theUnit[0]);
else if (Billion == 1e6 || Billion == 1e2)
printf("%c", theUnit[1]);
else if (Billion == 1e7 || Billion == 1e3)
printf("%c", theUnit[2]);
}
if (Billion == 1e4)
printf("%c", theUnit[3]);
else if (Billion == 1e8)
printf("%c", theUnit[4]);
{
if ((num - temp * Billion) / (Billion / 10) != 0)
printf("a");
}
else
{
printf("%c", theValue[temp]);
if (Billion == 1e5 || Billion == 1e1)
printf("%c", theUnit[0]);
else if (Billion == 1e6 || Billion == 1e2)
printf("%c", theUnit[1]);
else if (Billion == 1e7 || Billion == 1e3)
printf("%c", theUnit[2]);
}
if (Billion == 1e4)
printf("%c", theUnit[3]);
else if (Billion == 1e8)
printf("%c", theUnit[4]);
num -= temp * Billion;
Billion /= 10;
}
}
Billion /= 10;
}
}
return 0;
}
}
2)设计思路
3)本题调试过程碰到问题及解决办法
解决办法:需要对判断是否为0
4)运行结果截图