csp工資計算(3500以上的工資就要上稅哦!)

這個題看着非常常規,但是滿分需要考慮逆運算纔不會超時
在這裏插入圖片描述
下面是通過不斷累加來計算剛剛得出的工資,會超時只有80分!

#include<iostream>
#include<stdlib.h>
using namespace std;
int tax(int T){//未扣除稅的工資 ,常規計算 
    int sum,money=T-3500;
    if(money<=0){
    	return sum=0;//不交稅,返回 
	}
	else if(money>80000){
		sum=(T-3500-80000)*0.45+(80000-55000)*0.35+(55000-35000)*0.3+(35000-9000)*0.25+(9000-4500)*0.2+(4500-1500)*0.1+1500*0.03;
	}
	else if(money>55000){
		sum=(T-3500-55000)*0.35+(55000-35000)*0.3+(35000-9000)*0.25+(9000-4500)*0.2+(4500-1500)*0.1+1500*0.03;
	}
	else if(money>35000){
		sum=(T-3500-35000)*0.3+(35000-9000)*0.25+(9000-4500)*0.2+(4500-1500)*0.1+1500*0.03;
	}
	else if(money>9000){
		sum=(T-3500-9000)*0.25+(9000-4500)*0.2+(4500-1500)*0.1+1500*0.03;
	}
	else if(money>4500){
		sum=(T-3500-4500)*0.2+(4500-1500)*0.1+1500*0.03;
	}
	else if(money>1500){
		sum=(T-3500-1500)*0.1+1500*0.03;
	}
	else{
		sum=(T-3500-1500)*0.03;
	}
	return T-sum;//返回扣除稅的工資 
}
int main(){
	system("color 3");
	int T;
	cin>>T;
	int temp=T/100*100;//化爲整百 
	while(1){
		if(tax(temp)==T){
			break;
		}
		temp+=100;//整百輸入
	}
	cout<<temp;
	return 0;
}

在這裏插入圖片描述
在這裏插入圖片描述
雖然正確,但是這樣碰撞明顯超時啦!
待修改……

發佈了84 篇原創文章 · 獲贊 108 · 訪問量 7903
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章