|
发表于 2020-5-5 11:45: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;
}
==================================
==================================
#include <stdio.h>
main()
{
char *ch[11];
ch[0]="\0";ch[1]="一";ch[2]="二";ch[3]="三";ch[4]="四";
ch[5]="五";ch[6]="六";ch[7]="七";ch[8]="八";ch[9]="九";ch[10]="零";
char *dw[6];
dw[2]="十";dw[3]="百";dw[0]="千";dw[5]="万";dw[4]="亿";dw[1]="\0";
char number[11];int last,n,m,i,j,have;
while(1)
{
scanf("%s",number);
last = 1;have = 0;
for(i=0;i<11&&number[i]!='\0';i++);
for(j=0;j<i;j++)
{
n = number[j]-48;
m = i-j;
if(have == 0&& m>4 && m<9 && n) have =1;
if(last == 0 && n) printf(ch[10]);
printf(ch[n]); if(n) printf(dw[m%4]);
if(m%4 == 1)
{
if( m == 5 && have) printf(dw[5]);
if( m == 9 ) printf(dw[4]);
}
last = n;
}
printf("\n");
}
}
|
|