欢迎访问我的CCF认证解题目录
题目描述
思路过程
由题目可知税率和税后工资,那么我们通过这个公式即可求出税前工资,税前工资 - 税前工资 * 税率 = 得到的工资
,转化得到 税前工资 = 得到的工资 / ( 1 - 税率 )
代码
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double[] tax = {0, 0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45};//税率
int[] cost = {0, 3500, 5000, 8000, 12500, 38500, 58500, 83500, Integer.MAX_VALUE};//价钱区间
int money = in.nextInt();//税后的钱
int ans = 0;//结果
for ( int i = 1; i < cost.length && money != 0; i++ ) {
int section = cost[i] - cost[i-1];//区间
if ( money / ( 1 - tax[i-1] ) > section ) {//如果税前的钱能超过这个区间
money -= section * ( 1 - tax[i-1] );//减去相应的税前的钱
ans += section;//加上税后该区间的钱
} else {
ans += money / ( 1 - tax[i-1] );//加上税后该区间的钱
money = 0;
}
}
System.out.println(ans);
}
}