1943 - 行礼托运
Time Limit : 1 秒
Memory Limit : 128 MB
某车站行李托运收费标准是:10公斤或10公斤以下,收费2.5元,超过10公斤的行李,按每超过1公斤增加1.5元进行收费。 试编写一程序,输入行李的重量,算出托运费(小数点后面保留一位)。
Input
一行:1个实型数据,表示行李重量。
Output
一行:1个实型数据,表示托运费用(小数点后保留1位)。
Examples
Input Format
10
Output Format
2.5
Solution C
#include <stdio.h> int main(){ float weight; float money; scanf("%f",&weight); if(weight<=10) money=2.5; else money=2.5+(weight-10)*1.5; printf("%.1f\n",money); return 0;}
Solution C++
#include<iostream> #include<cstdio> //standard input output using namespace std; int main() { float w,fee; cin>>w; if (w<=10) fee=2.5; else fee=2.5+(w-10)*1.5; cout.precision(1); //设置输出格式,小数点后保留1位 cout.setf(ios::fixed); cout<<fee<<endl; return 0; }