当前位置:网站首页>2303. 计算应缴税款总额
2303. 计算应缴税款总额
2022-07-02 12:10:00 【紫菜(Nori)】
class Solution {
public:
double calculateTax(vector<vector<int>>& brackets, int income) {
double ans = 0;
for(int i = brackets.size() - 1; i > 0; --i){
auto &vec = brackets[i];
auto &vec1 = brackets[i - 1];
// 当income不在这个区间时直接跳过
if(vec[0] > income && vec1[0] > income){
continue;
}
// 中间的差值
int diff = income - vec1[0];
// 这部分差值所应该交的税,这里是实际值的100倍
ans += (diff * vec[1]);
// 当前剩余未计算的income
income = vec1[0];
}
// 计算最小的范围,应交的税,这里是实际值的100倍
ans += (income * brackets[0][1]);
// 计算实际税
ans /= 100;
return ans;
}
};边栏推荐
- Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
- Loss function and positive and negative sample allocation: Yolo series
- 21_ Redis_ Analysis of redis cache penetration and avalanche
- Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
- 【LeetCode】1905-统计子岛屿
- 18_ Redis_ Redis master-slave replication & cluster building
- 04.进入云原生后的企业级应用构建的一些思考
- yolo格式数据集处理(xml转txt)
- 06_ Stack and queue conversion
- Redux——详解
猜你喜欢
随机推荐
15_Redis_Redis.conf详解
怎样从微信返回的json字符串中截取某个key的值?
Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
Force deduction solution summarizes the lucky numbers in 1380 matrix
Summary of the first three passes of sqli Labs
14_Redis_乐观锁
02_线性表_顺序表
Bing. Site Internet
Wechat Alipay account system and payment interface business process
17_ Redis_ Redis publish subscription
How to intercept the value of a key from the JSON string returned by wechat?
19_Redis_宕机后手动配置主机
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
Leetcode skimming -- count the number of numbers with different numbers 357 medium
How to find a sense of career direction
2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
【LeetCode】695-岛屿的最大面积
Huffman tree: (1) input each character and its weight (2) construct Huffman tree (3) carry out Huffman coding (4) find hc[i], and get the Huffman coding of each character
MD5加密
21_ Redis_ Analysis of redis cache penetration and avalanche









