201612-2 工资计算 Java

思路:
税+税后所得A=税前工资S。
因为工资是整百的数,每次减100来判断。好理解但是超时。

import java.util.Scanner;
//只有90分,超时了
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		if(T < 3500) {
			System.out.println(T);
		}
		double x = 0;//税钱
		int S = 200000;//假设一个月最多挣20万
		int A = S - 3500;
		while(true)
	    {
	        if(A <= 1500)
	            x = A * 0.03;
	        else if(A <= 4500)
	            x = 45 + (A - 1500) * 0.1;
	        else if(A <= 9000)
	            x = 45 + 300 + (A - 4500) * 0.2;
	        else if(A <= 35000)
	            x = 45 + 300 + 900 + (A - 9000) * 0.25;
	        else if(A <= 55000)
	            x = 45 + 300 + 900 + 6500 + (A - 35000) * 0.3;
	        else if(A <= 80000)
	            x = 45 + 300 + 900 + 6500 + 6000 + (A - 55000) * 0.35;
	        else
	            x = 45 + 300 + 900 + 6500 + 6000 + 8750 + (A - 80000) * 0.45;
	        if(S == x + T)
	            break;
	        S = S - 100;
	        A = S - 3500;
	    }
		System.out.println(S);
	}

}
posted @ 2020-02-26 12:36  菜鸡A  阅读(312)  评论(0编辑  收藏  举报