这题不知道错哪里,求大神提点
查看原帖
这题不知道错哪里,求大神提点
1306363
coder_Jackson楼主2024/4/5 13:21
#include <iostream>  
#include <iomanip>  
using namespace std;  

int main() {  
	double d; // 乘车距离,单位为千米  
	int w; // 等待时间,单位为分钟  
	cin >> d >> w; // 读取乘车距离和等待时间
	
	double c = 6.0, e = 6.0, f = 6.0;
	// 不超2千米时的费用(起步价,e为超过10千米时的费用,f为不超2千米时的费用)
	if(d <= 2)
    {
		if (w > 0) 
			f += w / 3; // 每3分钟计费1元,不满3分钟不计费
        cout << fixed << setprecision(2) << f << endl;	
	}
	// 超过2千米后的费用
	if (d > 2) 
    {
		c += (d - 2) * 1.8; // 超过2千米的部分按1.8元/千米收费
		if (w > 0) 
			c += w / 3; // 每3分钟计费1元,不满3分钟不计费	
		cout << fixed << setprecision(2) << c << endl;
	}
	if (d > 10) 
    {
		e += (10 - 2) * 1.8;
		e += (d - 10) * (1.8 * 1.5); 
		if (w > 0) 
			e += w / 3; // 每3分钟计费1元,不满3分钟不计费	
		cout << fixed << setprecision(2) << e << endl;
	}
	return 0;
}
2024/4/5 13:21
加载中...