文章

1

粉丝

135

获赞

3

访问

5.7k

头像
1040 利润提成 北京大学机试题
P1040 北京大学机试题
发布于2022年7月10日 18:56
阅读数 5.7k

主要思路是将利率和梯度用数组进行存储,然后用while找到利润在的最高梯度位置,先进行单独计算,下面的再进行循环计算。

#include<iostream>

using namespace std;

int main(){
	int profit, bonus = 0, index=0;
	cin >> profit;
	double rate[6] = {10, 7.5, 5, 3, 1.5, 1};
	int table[6] = {0, 100000, 200000, 400000, 600000, 1000000};
	while(profit>table[index])
		index++;
	if(index >=1)
	bonus += (profit - table[index-1])*rate[index-1];
	while(index--)
		bonus += (table[index]-table[index-1] )*rate[index-1];
	cout <<  bonus*0.01;
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发