原题链接:[编程入门]利润计算
解题思路:
用一系列if else语句来处理多种情况。因为分段不太方便所以没用switch语句,不过用除以200000的余数来作为case应该也可以。
注意事项:
奖金应为浮点数,因为可能有小数。数额比较大,计算比较繁琐。
参考代码:
#include <iostream>
using namespace std;
int main() {
	int profit = 0;
	float award = 0;
	cin >> profit;
	if(profit < 0) {
		return -1;
	} else if(profit <= 100000) {
		award = 0.1 * profit;
	} else if(profit <= 200000) {
		award = 0.075 * (profit - 100000) + 10000;
	} else if(profit <= 400000) {
		award = 0.05 * (profit - 200000) + 17500;
	} else if(profit <= 600000) {
		award = 0.03 * (profit - 400000) + 27500;
	} else if(profit <= 1000000) {
		award = 0.015 * (profit - 600000) + 33500;
	} else {
		award = 0.01 * (profit - 1000000) + 39500;
	}
	cout << award << endl;
	return 0;
}0.0分
3 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
 
@qss @reminder #include<iostream> using namespace std; int main(){ int x=0; float y=0; int x, y; cin >> x; if(x<0){ return -1; } else if(x <= 100000) y = x * 0.1; else if(x < 200000) y = (x - 100000) * 0.075 + 100000 * 0.1; else if(x < 400000) y = (x - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; else if(x < 600000) y = (x - 400000) * 0.03 + (400000 - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; else if(x < 1000000) y = (x - 600000) * 0.015 + (600000 - 400000) * 0.03 + (400000 - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; else y = (x - 1000000) * 0.01 + (1000000 - 600000) * 0.015 + (600000 - 400000) * 0.03 + (400000 - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; cout << y; return 0; }@qss @reminder #include<iostream> using namespace std; int main(){ int x=0; float y=0; int x, y; cin >> x; if(x<0){ return -1; } else if(x <= 100000) y = x * 0.1; else if(x < 200000) y = (x - 100000) * 0.075 + 100000 * 0.1; else if(x < 400000) y = (x - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; else if(x < 600000) y = (x - 400000) * 0.03 + (400000 - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; else if(x < 1000000) y = (x - 600000) * 0.015 + (600000 - 400000) * 0.03 + (400000 - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; else y = (x - 1000000) * 0.01 + (1000000 - 600000) * 0.015 + (600000 - 400000) * 0.03 + (400000 - 200000) * 0.05 + (200000 - 100000) * 0.075 + 100000 * 0.1; cout << y; return 0; }