税率计算

来源:互联网 发布:appstore下载不了软件 编辑:程序博客网 时间:2024/06/02 17:58

问题描述:

For incomes from wages and salaries, the progressive tax rate in excess of specific amount is applicable. The income amount taxable shall be the remainder after deducting 3500 yuan from the monthly income. The tax rate is below:

Grade Monthly Taxable Income
Tax Rate(%)
Income of 1,500 yuan or less
3%
That part of income in excess of 1,500 to 4,500 yuan
10%
That part of income in excess of 4,500 to 9,000 yuan
20%
That part of income in excess of 9,000 to 35,000 yuan
25%
That part of income in excess of 35,000 to 55,000 yuan
30%
That part of income in excess of 55,000 to 80,000 yuan
35%
That part of income in excess of 80,000 yuan
45%
Given the tax Little Hi paid, do you know his salary this month?

输入
Line 1: M, the tax Little Hi paid. (1 <= M <= 5,000,000)

输出
Line 1: Little Hi’s salary. The number should be rounded dowm to the nearest integer.

提示
Little Hi’s salary is 15692 yuan. The tax is calculated below:
The income amount taxable is 15692 - 3500 = 12192 yuan.
That part of income of 1500 or less: 1500 * 3% = 45 yuan.
That part of income in excess of 1,500 to 4,500 yuan: 3000 * 10% = 300 yuan.
That part of income in excess of 4,500 to 9,000 yuan: 4500 * 20% = 900 yuan.
That part of income in excess of 9,000 to 35,000 yuan: (12192 - 9000) * 25% = 798 yuan.
Total tax is 45 + 300 + 900 + 798 = 2043 yuan.

注意本题中,税率计算时是分段的所以,每次加的值是增量。另外为了编程方便,可以在数组头加上0,收入最大值写上float最大值。

#include <cstdio>#include <algorithm>#include <cmath>#include <limits>float rate[] = {0, 0.03, 0.10, 0.20, 0.25, 0.30, 0.35, 0.45};float income[] = {0, 1500, 4500, 9000, 35000, 55000, 80000, std::numeric_limits<float>::max()};int main(){    float tax;    float salary;    scanf("%f", &tax);    salary = 3500;    for (int i = 1; i< sizeof(rate)/sizeof(float); i++)    {        float maxTax = (income[i] - income[i-1]) * rate[i];        if (tax > maxTax)        {            salary += income[i]- income[i-1];            tax -= maxTax;        }        else{            salary += tax / rate[i];            break;        }    }    printf("%d\n", (int)floorf(salary));}
0 0
原创粉丝点击