C++ this is the second problem Continuing the last one. thx a lot

C++ this is the second problem Continuing the last one. thx a lot

题目
C++ this is the second problem Continuing the last one. thx a lot
Problem 2*
Continuing the discussion of the previous example, we reiterate the importance of designing check-writing systems to prevent alteration of check amounts. One common security method requires that the check amount be written both in numbers, and spelled out in words as well. Even if someone is able to alter the numerical amount of the check, it is extremely difficult to change the amount in words. Many computerized check-writing systems do not print the amount of the check in words. Perhaps the main reason for this omission is the fact that most high-level languages used in commercial applications do not contain adequate string manipulation features. Another reason is that the logic for writing word equivalents of check amounts is somewhat involved. Write a C++ program that inputs a numeric check amount and writes the word equivalent of the amount.
For example, the amount 112.43 should be written as ONE HUNDRED TWELVE AND 43/100 DOLLARS. Your program should be able to handle amounts up to 1 million dollars.
答案
#include
#include
char unit[4][33]={"","THOUSAND","MILLION"};
char low[10][33]={"ZERO","ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
char two[10][33]={"TEN","ELEVEN","TWELVE","THIRTTEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN"};
char high[10][33]={"ZERO","TEN","TWENTY","THIRTY","FORTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINETY"};
char hd[33]="HUNDRED";
void trans(int n,int deep)
{
char dig[100]={0};
if(n==0)return ;
if(n/100>0)
{
strcat(dig,low[n/100]);
strcat(dig," ");
strcat(dig,hd);
strcat(dig," ");
}
n%=100;
if(n==0)
{
;
}
else if(n0)
{
strcat(dig,unit[deep]);
strcat(dig," ");
}
printf("%s",dig);
}
void out(int n,int deep)
{
if(n==0)return;
out(n/1000,deep+1);
trans(n%1000,deep);
}
int main()
{
int sum=0;
int T,n=0,i;
char s[1000];
scanf("%s",s);
for(i=0;s[i]!='.';i++)n=n*10+s[i]-'0';
for(i++;s[i];i++)sum=sum*10+s[i]-'0';
if(n==0)
{
printf("ZERO ");
}
else out(n,0);
printf("AND %d/100",sum);
return 0;
}
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.