#include <stdio.h>
float dj=2.3;
float num(int a,int b,int c);
int main()
{
printf("%f",num(9,6,12));
return 0;
}
float num(int a,int b,int c){
float zh=0;
if((a>=23&&a<=24)||(a>=0&&a<5)){
if(c<=3){
zh+= 13;
}else{
zh+= c*(dj*1.2)+1;
}
}else{
if(c<=3){
zh+= 13;
}else{
zh+= c*dj+1;
}
}
if((b>=23&&b<=24)||(b>=0&&b<5)){
if(c<=3){
zh+= 13;
}else{
zh+= c*(dj*1.2)+1;
}
}else{
if(c<=3){
zh+= 13;
}else{
zh+= c*dj+1;
}
}
return zh;
};
if((a>=23&&a<=24)||(a>=0&&a<5)){
if(c<=3){
zh+= 13;
}else{
zh+= c*(dj*1.2)+1;
}
}else{
if(c<=3){
zh+= 13;
}else{
zh+= c*dj+1;
}
}
if((b>=23&&b<=24)||(b>=0&&b<5)){
if(c<=3){
zh+= 13;
}else{
zh+= c*(dj*1.2)+1;
}
}else{
if(c<=3){
zh+= 13;
}else{
zh+= c*dj+1;
}
}
单纯从你的代码看 ,
排除特殊计费情况(比如你4:58上车, 5点多下车 ,跨临界值情况)。
這2段可以优化一下。
if(((a>=23&&a<=24)||(a>=0&&a<5)) or ((b>=23&&b<=24)||(b>=0&&b<5))){
if(c<=3){
zh+= 13;
}else{
zh+= c*(dj*1.2)+1;
}
}else{
if(c<=3){
zh+= 13;
}else{
zh+= c*dj+1;
}
}
就可以了,跟你的是一样的。