游客 Signup | Login
中文 | En

3264 - 例题4-10 运费计算

运输公司对用户计算运输费用。路程(km)越远(以s表示),每吨.千米的运费越低。

计算标准如下:

设基本运费为p,货物重量为w,运输距离为s,折扣率为d,则总运费f的计算公式如下:

 

 

Input

输入运输单价、重量和距离,以空格分隔。

数据类型定义为float类型。

Output

freight=计算出的总运费。

小数点后保留2位数字,末尾输出换行。

Examples

Input

100 20 300

Output

freight=588000.00

Solution C

#include<stdio.h>
int main()
{
	float p,w,s,d,f;
	scanf("%f%f%f",&p,&w,&s);
	if(s<250) d=0;
	if(s>=250&&s<500) d=0.02;
	if(s>=500&&s<1000) d=0.05;
	if(s>=1000&&s<2000) d=0.08;
	if(s>=2000&&s<3000) d=0.1;
	if(s>=3000) d=0.15;
	f=p*w*s*(1-d);
	printf("freight=%.2f\n",f);
	getchar();
	getchar();
	return 0;
}

Solution C++

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	float p,w,s,d,f;
	int c;
	cin>>p>>w>>s;
	if (s>=3000) c=12;
	else c=int(s/250);
	switch (c)
	{
		case 0:  d=0;	break;
		case 1:	 d=2;	break;
		case 2:
		case 3:	 d=5;	break;
		case 4:
		case 5:
		case 6:
		case 7:	 d=8;	break;
		case 8:
		case 9:
		case 10:
		case 11: d=10;	break;
		case 12: d=15;	break;
	}
	f=p*w*s*(1-d/100);
	printf("freight=%.2f\n",f);
	return 0;
}
Time Limit 1 second
Memory Limit 12 MB
Discuss Stats
上一题 下一题