-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProblema_1051.cpp
52 lines (43 loc) · 932 Bytes
/
Problema_1051.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
/*
@autor: Victor E. B. Rodrigues;
@data: 23/06/2021;
@nome: Imposto de Renda;
*/
#include <bits/stdc++.h>
#include <iomanip>
#include <stack>
using namespace std;
double getIR(double& sal, stack<double>& pilha, stack<double>& pilha2){
static double ir = 0;
if(!pilha.empty()){
if(sal > pilha.top()){
ir+= (sal - pilha.top()) * pilha2.top();
sal = pilha.top();
}
pilha.pop();
pilha2.pop();
getIR(sal, pilha, pilha2);
}
return ir;
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
stack<double> pilha, pilhaIR;
pilha.push(2000);
pilha.push(3000);
pilha.push(4500);
pilhaIR.push(0.08);
pilhaIR.push(0.18);
pilhaIR.push(0.28);
double salario;
cin >> salario;
cout << setprecision(2) << fixed;
double impostoRenda = getIR(salario, pilha, pilhaIR);
if(impostoRenda == 0)
cout << "Isento" << endl;
else
cout << "R$ " << impostoRenda << endl;
return 0;
}