# 算法优化——进阶税率

0
[待解决问题]
```#include <iostream>
#pragma warning(disable:4703)
using namespace std;
/* 计算税款，根据美国2002年的数据
说实话连人家的这些例子都觉得特别棒！！！
*/

int singleFilers[5] = { 6000, 27950, 67700, 141250, 307050 };
int marriedFileJointly[5] = {12000,46700,112850,171950,307050};
int marriedFileSeparately[5] = { 6000, 23350, 56425, 85975, 153525 };
int headOfHousehold[5] = { 10000, 37450, 96700, 15600, 307050 };
#define stageOne 10.0
#define stageTwo 15.0
#define stageThree 27.0
#define stageFour 30.0
#define stageFive 35.0
#define stageSix 38.6
double taxStageRate[6] = { stageOne / 100, stageTwo / 100, stageThree/100, stageFour/100, stageFive/100, stageSix/100 };

double getTax(double money, int* moneyStage, double* taxRateStage){

}

/*
根据这个人的状态和 挣到的钱，来决定纳税金额。
现在的想法就是是不是可以因为这一组数据很有规律，所以想做一个数组，来规范这样的话，只需要根据不同的状态，来分不同的税率阶段就可以了
*/
double getTax(int status,double money){
int* MoneyStage;
if (status == 0){
MoneyStage = singleFilers;
}
else if(status ==1){
MoneyStage = marriedFileJointly;
}
else if (status ==2){
MoneyStage = marriedFileSeparately;
}
else if (status == 3){
}
double tax = 0;
if (money <= MoneyStage[0]){
tax = (money-0)*taxStageRate[0];//10
}
else if (money <= MoneyStage[1]){

tax = MoneyStage[0] * taxStageRate[0] + (money - MoneyStage[0]) * taxStageRate[1];//6000*10+(money-6000)*15
}
else if (money <= MoneyStage[2]){
tax = MoneyStage[0] * taxStageRate[0] + (MoneyStage[1] - MoneyStage[0]) * taxStageRate[1] + (money - MoneyStage[1])*taxStageRate[2];
}
else if (money <= MoneyStage[3]){
tax = MoneyStage[0] * taxStageRate[0] + (MoneyStage[1] - MoneyStage[0]) * taxStageRate[1] + (MoneyStage[2] - MoneyStage[1]) * taxStageRate[2] + (money - MoneyStage[2])*taxStageRate[3];
}
else if (money <= MoneyStage[4]){
tax = MoneyStage[0] * taxStageRate[0] + (MoneyStage[1] - MoneyStage[0]) * taxStageRate[1] + (MoneyStage[2] - MoneyStage[1]) * taxStageRate[2] + (MoneyStage[3] - MoneyStage[2]) * taxStageRate[3] + (money - MoneyStage[3])*taxStageRate[4];
}
else{
tax = MoneyStage[0] * taxStageRate[0] + (MoneyStage[1] - MoneyStage[0]) * taxStageRate[1] + (MoneyStage[2] - MoneyStage[1]) * taxStageRate[2] + (MoneyStage[3] - MoneyStage[2]) * taxStageRate[3] + (MoneyStage[4] - MoneyStage[3]) * taxStageRate[4] + (money - MoneyStage[4])*taxStageRate[5];
}
tax = getTax(money,MoneyStage,taxStageRate);

return tax;
}

int main(){

cout << getTax(0, 400000);
system("pause");
return 0;
}```

0

if (status == 0){
MoneyStage = singleFilers;

auto _Iter = std::find_if(std::cbegin(MoneyStage),std::cend(MoneyStage),

[money](int _Stage) {

return money < _Stage;

});

int key = _Iter == std::cend(MoneyState) ? INT_MAX : *_Iter;

auto _Func = std::unordered_map<int,std::function<double(double ,int * )>>::find(key);

auto tax = _Func(money,MoneyState);

Launcher | 园豆：45045 (高人七级) | 2016-04-13 10:46

您需要登录以后才能回答，未注册用户请先注册