过了(只是想……)
查看原帖
过了(只是想……)
1349478
tangyiqi楼主2024/7/9 17:22

过了,只是觉得这道题比较难,同时我也费劲九牛二虎之力才做出来的,我这份代码仅限学术参考,不可直接抄袭

#include <bits/stdc++.h>
using namespace std;
int a;
double price = 0.0;
double dian1(int x);//第一段的计费
double dian2(int x);//第二段的计费
double dian3(int x);//第三段的计费
void print(double x);//输出函数
int main(){
	scanf("%d",&a);
	if(a<=150)print(dian1(a));//运用函数嵌套,时间复杂度较高,所以不推荐使用(但真的很帅)
	else if(a>150 && a<=400)print(dian2(a));
	else print(dian3(a));
	return 0;
}
double dian1(int x){
	price+=x*1.0*0.4463;
	return price;
}
double dian2(int x){
	price+=1.0*0.4463*150+(x-150)*1.0*0.4663;
	return price;
}
double dian3(int x){
	price+=1.0*0.4463*150+(400-150)*1.0*0.4663+(x-400)*1.0*0.5663;
	return price;
}
void print(double x){
	printf("%.1lf",x);
}
2024/7/9 17:22
加载中...