某停车场收费标准如下:30分钟(含)内免费,前3小时收费3元,以后每半小时(含)加1.5元,24小时(含)最高收费30元,如果超过24小时,则按每天30元计算。
请设计程序输入停车分钟数(整数),输出收费金额(以元为单位,结果保留两位小数)。
例如停车40分钟,收费3元,则
输入
30
输出
3.00
以下是一些测试样例的输入
10
30
31
180
181
211
690
691
800
则分别应该输出
price=0.00
price=0.00
price=3.00
price=3.00
price=4.50
price=6.00
price=28.5
price=30.00
price=30.00
代码如下
#include<stdio.h>
//等于强制int,原样输出,不等于,加一输出
int main()
{
double t,price;
while(1)
{
scanf("%lf",&t);
if(t<=30)
{
price = 0;
}
else if(t>30&&t<=180)
{
price = 3;
}
else if(t>180&&t<=690)
{
t=(t-180)/30;
if(t==(int)t)
{
price = 3+t*1.5;
}
else
{
price = 3+((int)t+1)*1.5;
}
}
else if(t>690&&t<=1440)
{
price = 30;
}
else
{
t=(t-1440)/(60*24);
if(t==(int)t)
{
price = 30+t*30;
}
else
{
price = 30+((int)t+1)*30;
}
}
printf("price=%.2f",price);
}
return 0;
}
代码运行截图与样例对比如下