URI Online Judge | 1021
Banknotes and Coins
By Neilor Tonin, URI Brazil
Timelimit: 1
Read a value of floating point with two decimal places. This represents a monetary value. After this, calculate the smallest possible number of notes and coins on which the value can be decomposed. The considered notes are of 100, 50, 20, 10, 5, 2. The possible coins are of 1, 0.50, 0.25, 0.10, 0.05 and 0.01. Print the message “NOTAS:” followed by the list of notes and the message “MOEDAS:” followed by the list of coins.
Input
The input file contains a value of floating point N (0 ≤ N ≤ 1000000.00).
Output
Print the minimum quantity of banknotes and coins necessary to change the initial value, as the given example.
Input Sample | Output Sample |
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 |
4.00 | NOTAS: 0 nota(s) de R$ 100.00 0 nota(s) de R$ 50.00 0 nota(s) de R$ 20.00 0 nota(s) de R$ 10.00 0 nota(s) de R$ 5.00 2 nota(s) de R$ 2.00 MOEDAS: 0 moeda(s) de R$ 1.00 0 moeda(s) de R$ 0.50 0 moeda(s) de R$ 0.25 0 moeda(s) de R$ 0.10 0 moeda(s) de R$ 0.05 0 moeda(s) de R$ 0.01 |
91.01 | NOTAS: 0 nota(s) de R$ 100.00 1 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 0 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 |
URI Online Judge Solution 1021 || Banknotes and Coins in C++ language
#include <iostream>
using
namespace
std;
int
main() {
double
n100, n50, n20, n10, n5, n2;
double
m1, m50, m25, m10, m05, m01;
double
n;
cin >> n;
int
notas = n;
int
moedas = (n - notas) * 100;
if
((moedas * 1000) % 10 == 9){
moedas++;
}
n100 = notas/100;
notas = notas%100;
n50 = notas/50;
notas = notas%50;
n20 = notas/20;
notas = notas%20;
n10 = notas/10;
notas = notas%10;
n5 = notas/5;
notas = notas%5;
n2 = notas/2;
notas = notas%2;
m1 = notas/1;
notas = notas%1;
m50 = moedas/50;
moedas = moedas%50;
m25 = moedas/25;
moedas = moedas%25;
m10 = moedas/10;
moedas = moedas%10;
m05 = moedas/5;
moedas = moedas%5;
m01 = moedas/1;
cout <<
"NOTAS:"
<< endl;
cout << n100 <<
" nota(s) de R$ 100.00"
<< endl;
cout << n50 <<
" nota(s) de R$ 50.00"
<< endl;
cout << n20 <<
" nota(s) de R$ 20.00"
<< endl;
cout << n10 <<
" nota(s) de R$ 10.00"
<< endl;
cout << n5 <<
" nota(s) de R$ 5.00"
<< endl;
cout << n2 <<
" nota(s) de R$ 2.00"
<< endl;
cout <<
"MOEDAS:"
<< endl;
cout << m1 <<
" moeda(s) de R$ 1.00"
<< endl;
cout << m50 <<
" moeda(s) de R$ 0.50"
<< endl;
cout << m25 <<
" moeda(s) de R$ 0.25"
<< endl;
cout << m10 <<
" moeda(s) de R$ 0.10"
<< endl;
cout << m05 <<
" moeda(s) de R$ 0.05"
<< endl;
cout << m01 <<
" moeda(s) de R$ 0.01"
<< endl;
return
0;
}
See or download code from dropboxIf adfly Happened just skip that kindly
See Question in URI OJ
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks