#include #include#include#include
int getNumLen(longlNum)
{int nLen = 0;while(lNum / 10 >= 0)
{
lNum/= 10;
nLen++;
}returnnLen;
}#define MAX_SIZE 0x500std::stringg_Output;void Trans1(intn)
{switch(n)
{case 1:
g_Output+= "one";break;case 2:
g_Output+= "two";break;case 3:
g_Output+= "three";break;case 4:
g_Output+= "four";break;case 5:
g_Output+= "five";break;case 6:
g_Output+= "six";break;case 7:
g_Output+= "seven";break;case 8:
g_Output+= "eight";break;case 9:
g_Output+= "nine";break;
}
}void Trans2(intn)
{switch(n)
{case 0:
g_Output+= "ten";break;case 1:
g_Output+= "eleven";break;case 2:
g_Output+= "twelve";break;case 3:
g_Output+= "threeteen";break;case 4:
g_Output+= "fourteen";break;case 5:
g_Output+= "fifteen";break;case 6:
g_Output+= "sixteen";break;case 7:
g_Output+= "seventeen";break;case 8:
g_Output+= "eighteen";break;case 9:
g_Output+= "nineteen";break;
}
}void Trans3(intn)
{switch(n)
{case 2:
g_Output+= "twenty";break;case 3:
g_Output+= "thirty";break;case 4:
g_Output+= "forty";break;case 5:
g_Output+= "fifty";break;case 6:
g_Output+= "sixty";break;case 7:
g_Output+= "seventy";break;case 8:
g_Output+= "eighty";break;case 9:
g_Output+= "ninety";break;
}
}void Trans(intlHigh)
{if(lHigh / 100 > 0)
{
Trans1(lHigh/ 100);
g_Output+= "hundred";
lHigh%= 100;if(lHigh > 0)
{
g_Output+= "and";
}
}if(lHigh / 10 > 0)
{if(lHigh / 10 == 1)
{
Trans2(lHigh% 10);return;
}
Trans3(lHigh/ 10);
}
lHigh%= 10;if(lHigh)
{
Trans1(lHigh);
}return;
}int getLen(longlNum)
{int nCunt = 0;while(lNum)
{
nCunt++;
lNum/= 10;
}returnnCunt;
}intmain()
{char szInput[MAX_SIZE] = {0};while(scanf("%s", szInput) !=EOF)
{if(strlen(szInput) > 9)
{
printf("error");return 0;
}if(szInput[0] == '-')
{
printf("error");return 0;
}if(std::string(szInput).find('.') != -1)
{
printf("error");return 0;
}int nLen =strlen(szInput);long lNum =atol(szInput);if(0 ==lNum)
{
printf("zero");return 0;
}while(1)
{int lHigh = 0;if(nLen >= 7)
{
lHigh= lNum / 1000000;
Trans(lHigh);
lNum= lNum % 1000000;
g_Output+= "million";
nLen=getLen(lNum);
}else if(nLen >= 4)
{
lHigh= lNum / 1000;
Trans(lHigh);
lNum= lNum % 1000;
g_Output+= "thousand";
nLen=getLen(lNum);
}else{
Trans((int)lNum);break;
}
}
memset(szInput,0, MAX_SIZE);
printf("%s", g_Output.c_str());
g_Output.clear();
}//system("pause");
return 0;
}