-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2303.cpp
More file actions
25 lines (23 loc) · 771 Bytes
/
2303.cpp
File metadata and controls
25 lines (23 loc) · 771 Bytes
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
class Solution {
public:
double calculateTax(vector<vector<int>>& brackets, int income) {
if (income == 0) return 0.0;
double tax = 0.0;
// first
int firstTax = brackets[0][0];
double firstRate = brackets[0][1];
int firstPay = min(income, firstTax);
tax += (double)firstPay * firstRate / 100;
income -= firstPay;
int index = 1;
while (income != 0) {
int firstTax = brackets[index][0] - brackets[index - 1][0];
double firstRate = brackets[index][1];
int firstPay = min(income, firstTax);
tax += (double)firstPay * firstRate / 100;
income -= firstPay;
index++;
}
return tax;
}
};