if(w<=10)y=0.1*w;?elseif(w<=20)y=(w-10)*0.075+1;?elseif(w<=40)y=(w-20)*0.05+1.75;?elseif(w<=60)y=(w-40)*0.03+2.75;?elseif(w<=100)y=(w-60)*0.015+3.35;?elsey=(w-60)*0.01+3.95;?cout<<fixed<<setprecision(6)<<y<<endl;?return0;}出租车费难点:不足一公里按一公里收费。【ceil函数】法一【“%”取余的充分运用】#include<iostream>#include<iomanip>usingnamespacestd;intmain(){?doubles,y;?inta,b,c;?cin>>s;?c=s;?a=s*10;?b=a%10;?if(s<=2)y=7;?elseif(s<=15){ if(b==0)y=7+1.5*(s-2); elsey=7+1.5*(c-1);?}?else{ if(b==0)y=26.5+2.1*(s-15); elsey=26.5+2.1*(c-14);?}?cout<<fixed<<setprecision(6)<<y<<endl;?return0;}法二【ceil函数】#include<iostream>#include<cmath>#include<iomanip>usingnamespacestd;intmain(){?doubles,y;?inta;?cin>>s;?a=ceil(s);?if(s<=2)y=7;?elseif(s<=15){ y=7+1.5*(a-2);?}?else{ y=26.5+2.1*(a-15);?}?cout<<fixed<<setprecision(6)<<y<<endl;?return0;}