|
发表于 2020-1-28 04:00:02
|
显示全部楼层
//52367.23
//伍万贰仟叁佰陆拾柒元贰角叁分
#include <stdio.h>
#include <string.h>
char RMB[10][3]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
char value[13][3]={"零","拾","佰","仟","万","拾","百","千","亿","拾","佰","仟","万"};
char faction[2][3]={"角","分"};
void StyleChange(const char *str)
{
int i,j,k=1,t=0,s=0; //k用于指示当前操作的位置(十位、百位。。。)
int n;
char ValueSave[26][3]; //存储整数部分
char FactionValue[2][3]; //存储小数部分
n=strlen(str);
for(i=0;i<n;i++)
{
if(str[i]=='.')
break;
}
if(i>13)
{
printf("对不起请输入万亿位以下的数字\n");
return;
}
if(n-i>3)
{
printf("对不起请确保小数点后面两位\n");
return;
}
strcpy(ValueSave[t++],"元");
if((n-i>1&&i==1)||str[i-1]!='0')
strcpy(ValueSave[t++],RMB[str[i-1]-'0']);
for(j=i-2;j>=0;j--) //整数部分的操作
{
if(str[j]=='0')
{
if(str[j+1]!='0')
{
strcpy(ValueSave[t++],RMB[str[j]-'0']);
k++;
}
else
{
if(i>4&&k==8)
{
strcpy(ValueSave[t++],value[k]);
}
if(i<=8&&k==4)
{
strcpy(ValueSave[t++],value[k]);
}
k++;
}
continue;
}
strcpy(ValueSave[t++],value[k++]);
strcpy(ValueSave[t++],RMB[str[j]-'0']);
}
k=0; //小数部分的操作
for(j=i+1;j<n;j++)
{
strcpy(FactionValue[s++],RMB[str[j]-'0']);
strcpy(FactionValue[s++],faction[k++]);
}
for(j=t-1;j>=0;j--)
printf("%s",ValueSave[j]);
for(j=0;j<s;j++)
printf("%s",FactionValue[j]);
printf("\n");
}
int main()
{
char s[17];
int n;
while(gets(s)!=NULL)
{
n=strlen(s);
if(n>16)
{
printf("对不起请输入万亿位以下的数字\n");
return -1;
}
StyleChange(s);
}
return 0;
}
|
|