华为英语电脑测试软件,《牛客网》——华为机试在线训练——学英语

#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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值