-
Notifications
You must be signed in to change notification settings - Fork 1
/
Problema_1021.cpp
65 lines (53 loc) · 1.08 KB
/
Problema_1021.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
@autor: Victor E. B. Rodrigues;
@data: 22/06/2021;
@nome: Notas e Moedas;
*/
#include <bits/stdc++.h>
#include <stack>
using namespace std;
void printCedulas(double& n, stack<int>& pilha){
if(!pilha.empty()){
int valor = pilha.top();
int qtdCedulas = n/valor;
if (qtdCedulas > 0)
n -= qtdCedulas*valor;
cout << qtdCedulas << " nota(s) de R$ " << valor << ".00" << endl;
pilha.pop();
printCedulas(n, pilha);
}
}
void printMoedas(double& n){
cout << setprecision(2) << fixed;
int cont;
double vet[6] = {1, 0.5, 0.25, 0.1, 0.05, 0.01};
for(int i = 0; i<6; i++){
cont = int(n/vet[i]);
cout << cont << " moeda(s) de R$ " << vet[i] << endl;
if(cont>0){
n -= vet[i]*cont;
n *= 1000000.00;
n +=1;
n /= 1000000.00;
}
}
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
stack<int> pilha;
pilha.push(2);
pilha.push(5);
pilha.push(10);
pilha.push(20);
pilha.push(50);
pilha.push(100);
double n;
cin >> n;
cout << "NOTAS:" << endl;
printCedulas(n, pilha);
cout << "MOEDAS:" << endl;
printMoedas(n);
return 0;
}