#include <iostream>
using namespace std;
float BaseTax[100];
int LevelIncome[100];
float TaxRate[100];
int search(int LevelIncome[], int Income)
{
int i = 0;
int j = 99;
int t = (i + j) / 2;
while (1)
{
if (Income - LevelIncome[t] < 500 && Income - LevelIncome[t] >= 0)
return t;
else if (Income - LevelIncome[t] < 0)
{
j = t;
t = (i + j) / 2;
}
else
{
i = t;
t = (i + j) / 2;
}
}
return -1;
}
int main()
{
BaseTax[0] = 0;
LevelIncome[0] = 0;
TaxRate[0] = 0;
BaseTax[1] = 0;
LevelIncome[1] = 2200;
TaxRate[1] = 0.14;
for (int i = 2; i < 100; i++)
{
TaxRate[i] = (float)(14 + i - 1) / 100;
TaxRate[i] = (int)(TaxRate[i] * 100 + 0.5) / 100.0;
LevelIncome[i] = 2200 + (i - 1) * 500;
}
for (int i = 1; i < 100; i++)
{
BaseTax[i] = BaseTax[i - 1] + TaxRate[i] * (LevelIncome[i + 1] - LevelIncome[i]);
}
int salary = 4000;
int j = search(LevelIncome, salary);
double tax = BaseTax[j - 1] + TaxRate[j] * (salary - LevelIncome[j]);
cout << tax << endl;
system("pause");
return 0;
}