读取一个带有两个小数位的浮点数,这代表货币价值。
在此之后,将该值分解为多种钞票与硬币的和,每种面值的钞票和硬币使用数量不限,要求使用的钞票和硬币的数量尽可能少。
钞票的面值是100,50,20,10,5,2。
硬币的面值是1,0.50,0.25,0.10,0.05和0.01。
输入格式
输入一个浮点数N。
输出格式
参照输出样例,输出每种面值的钞票和硬币的需求数量。
数据范围
0≤N≤1000000.00
样例
576.73
样例输出
NOTAS:
5 nota(s) de R$ 100.00
1 nota(s) de R$ 50.00
1 nota(s) de R$ 20.00
0 nota(s) de R$ 10.00
1 nota(s) de R$ 5.00
0 nota(s) de R$ 2.00
MOEDAS:
1 moeda(s) de R$ 1.00
1 moeda(s) de R$ 0.50
0 moeda(s) de R$ 0.25
2 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
3 moeda(s) de R$ 0.01
代码
#include<stdio.h>
#include<math.h>
int main(){
double a[6]={100.00,50.00,20.00,10.00,5.00,2.00};
double b[5]={0.50,0.25,0.10,0.05,0.01};
double n;
scanf("%lf",&n);
int m=floor(n);//m=576
// printf("%d\n",m);
printf("NOTAS:\n");
for(int i=0;i<6;i++){
printf("%d nota(s) de R$ %.2lf\n",m/(int)a[i],a[i]);
m%=(int)a[i];
}
// printf("%d\n",m);//m=1
printf("MOEDAS:\n");
double h=n-floor(n);
// printf("%.2lf\n",h);//h=0.73
printf("%d nota(s) de R$ 1.00\n",m/1);
for(int i=0;i<5;i++){
printf("%d moeda(s) de R$ %.2lf\n",(int)(h/b[i]+0.00001),b[i]);
h-=((int)(h/b[i]+0.00001))*b[i];
//一定要加上0.00001,为了防止高精度问题
}
return 0;
}