问题描述
思路
更像是一道数学题
税率 | 税费(每阶段最高) | 税前(每阶段最高) | 税后(每阶段最高) |
---|---|---|---|
0 | 3500 | 3500 | |
(0,1500] — 3% | 45 | 5000 | 4955 |
(1500, 4500]—10% | 345 | 8000 | 7655 |
(4500,9000]—20% | 1245 | 12500 | 11255 |
(9000,35000]—25% | 7745 | 38500 | 30755 |
(35000,55000]—30% | 13745 | 58500 | 44755 |
(55000,80000]—35% | 22495 | 83500 | 61005 |
(80000,100000]—45% | 29920 | 100000 | 70080 |
以第三行为例:
阶段最高税费为 = 1500×3% + (4500-1500)×10% = 345
阶段税前最高 = 4500 + 3500 = 8000
阶段税后最高 = 8000 - 345 = 7655
样例输入:9255
此时7655 < 9255 < 11255
设税前工资为x,则x - 345 - (x - 8000)×20% = 9225
解得x = 10000
样例输出:10000
完整代码
#include<iostream>
using namespace std;
int main(){
int before;
int after;
cin >> after;
int before_max[8] = {3500, 5000, 8000, 12500, 38500, 58500, 83500, 100000};
int after_max[8] = {3500, 4955, 7655, 11255, 30755, 44755, 61005, 70080};
int tax_max[8] = {0, 45, 345, 1245, 7745, 13745, 22495, 29920};
float tax_rate[8] = {0, 0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45};
for( int i = 0; i < 8; i++)
{
if( after <= 3500 )
{
cout << after << endl;
break;
}
if( after >= after_max[i] && after <= after_max[i+1] )
{
for( before = before_max[i]; ; before += 100)
{
if( before - tax_max[i] - (before - before_max[i]) * tax_rate[i+1] == after)
{
cout << before << endl;
return 0;
}
}
}
}
return 0;
}