|
//52367.23
// Wu Wanzhang, San Bai Lu pick up Yuan Yuan corner three points
#include <stdio.h>
#include <string.h>
char RMB [10] [3] = {"Zero", "One", "贰", "Three", "Three", "Wu", "Lu", "柒", "捌", "玖"} ;
char value [13] [3] = {"zero", "pick up", "bai", "仟", "wan", "pick up", "hundred", "thousand", "billion", "pick up, "百", "仟", "万"};
char faction [2] [3] = {"角", "分"};
void StyleChange (const char * str)
{
int i, j, k = 1, t = 0, s = 0; // k is used to indicate the position of the current operation (tens, hundreds ...)
int n;
char ValueSave [26] [3]; // Store integer part
char FactionValue [2] [3]; // Store fractional part
n = strlen (str);
for (i = 0; i <n; i ++)
{
if (str [i] == '.')
break;
}
if (i> 13)
{
printf ("Sorry, please enter a number below 1 trillion digits\n");
return;
}
if (n-i> 3)
{
printf ("Sorry, please make sure 2uo1n after the decimal point");
return;
}
strcpy (ValueSave [t ++], "Meta");
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--) // Operation of integer part
{
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; // operation of decimal part
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 ("Sorry, please enter a number below 1 trillion digits\n");
return -1;
}
StyleChange (s);
}
return 0;
} |
|