Banknotes and coins
Problem Description
Reads a floating point number with two decimal places, which represent value for money.
After this, the value decomposition and more banknotes with coins, the use of an unlimited number of notes and coins of each denomination, the number of notes and coins required to use as little as possible.
Banknote par value of 100,50,20,10,5,2.
The face value of the coin is 1,0.50,0.25,0.10,0.05 and 0.01.
Input Format
Enter a floating-point number N.
Output Format
Referring to the number of output sample requirements, the output of each denomination of bills and coins.
data range
0≤N≤1000000.000≤N≤1000000.00
Sample input:
576.73
Sample output:
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
problem analysis
This problem increases the decomposition decimal, decimals should break down one by one, we must take into account more than the question of how to take a float, and floating point rounding problem
Code
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
//读取一个带有两个小数位的浮点数,这代表货币价值。
double m;//钱
cin>>m;
int mm=m*100;//将钱扩大100倍
int a[] = {10000, 5000, 2000, 1000, 500, 200};
int b[] = {100, 50, 25, 10, 5, 1};
cout<<"NOTAS:" <<endl;
for(int i=0;i<6;i++){
cout<<mm/a[i]<<" nota(s) de R$ "<<fixed<<setprecision(2)<<a[i]/100.00<<endl;
mm=mm%a[i];
}
cout<<"MOEDAS:" <<endl;
for(int i=0;i<6;i++){
cout<<mm/b[i]<<" moeda(s) de R$ "<<fixed<<setprecision(2)<<b[i]/100.00<<endl;
mm=mm%b[i];
}
return 0;
}
operation result
541.26
NOTAS:
5 nota(s) de R$ 100.00
0 nota(s) de R$ 50.00
2 nota(s) de R$ 20.00
0 nota(s) de R$ 10.00
0 nota(s) de R$ 5.00
0 nota(s) de R$ 2.00
MOEDAS:
1 moeda(s) de R$ 1.00
0 moeda(s) de R$ 0.50
1 moeda(s) de R$ 0.25
0 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
1 moeda(s) de R$ 0.01
to sum up
For this problem, using a round-robin fashion, logarithmic dismantling. And subject to the next decimal digits, then the original digital expansion
100倍
, and, while expanding the amount and denominations100倍
, then the output control precision, to achieve a floating point rounding and take the remainder.