题目描述:
2017/08/09 网易笔试
大概描述:计算分级税务要纳税多少计算一下即可
思路如下:
数组模拟计税过程即可
代码如下:
#include<stdio.h>
#include<iostream>
using namespace std;
int baseLine[7]={0, 3000, 12000, 25000, 35000, 55000, 80000};
double rate[8]={0, 3, 10, 20, 25, 30, 35, 45};
int CalTax(int income){
if(income<=5000)
return 0;
income-=5000;
double taxDouble=0;
int level;
for(level=0; level<7; level++){
if(income>baseLine[level])
continue;
break;
}
//level==7 || income<=baseLine[level]
for(int levelCur=1; levelCur<level; levelCur++){
taxDouble+=(1.0*rate[levelCur]/100)*(baseLine[levelCur]-baseLine[levelCur-1]);
}
taxDouble+=(1.0*rate[level]/100)*(income-baseLine[level-1]);
int taxInt=(int)(taxDouble*10);
if(taxInt%10>=5){
taxInt=taxInt/10+1;
}
else{
taxInt=taxInt/10;
}
return taxInt;
}
int main()
{
int N;
scanf("%d", &N);
for(int n=0; n<N; n++){
int income, tax;
scanf("%d", &income);
tax=CalTax(income);
printf("%d\n", tax);
}
return 0;
}