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;
}
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
- 甲乙两仓库共有棉花2600包,甲仓运走它的四分之三,乙仓运走它的五分之三,
- 来吃饭的是父母 阅读答案(原文及问题如下)
- 7.已知β1,β2是非齐次线性方程组Ax=b的两个不同的解,α1,α2是其导出组Ax=0的一个基础解系,C1,C2为任意常数,则方程组Ax=b的通解可以表为( )
- 溶液中的粒子运动是否有规律?如果没有,是做布朗运动吗
- Are your name Frank?哪里错了
- 用绳子测桥的高度.把绳子对折垂到水面沿余3米,把绳子三折后垂到水面上,沿余1米,桥的高度是多少米?
- protect from后面可以跟doing sth.
- 帮帮小弟做下数学题
- 动量守恒定律中的系统如何判断
- 关于这个视频中的所有化学实验
热门考点