第 27 題 - 解答


#include <stdio.h>
#include <math.h>
int main()
{
   int start_hour, start_min, end_hour, end_min;
   int total, fee; 
   
   printf("停車開始時間:"); 
   scanf("%d:%d",&start_hour,&start_min);
   printf("停車結束時間:"); 
   scanf("%d:%d",&end_hour,&end_min);
   total=(int)ceil(((end_hour*60+end_min)-(start_hour*60+start_min))/30.0);
   if(total<=4)
      fee=total*30;
   else if(total<=8)
      fee=4*30+(total-4)*40;
   else 
      fee=4*30+4*40+(total-8)*60;  
   printf("需繳交的停車費為%d元\n",fee);
   return 0;
}

考試版本
#include <stdio.h>
#include <math.h>
int main()
{
   int start_hour, start_min, end_hour, end_min;
   int total, fee; 
   
   scanf("%d:%d",&start_hour,&start_min);
   scanf("%d:%d",&end_hour,&end_min);
   total=(int)ceil(((end_hour*60+end_min)-(start_hour*60+start_min))/30.0);
   if(total<=4)
      fee=total*30;
   else if(total<=8)
      fee=4*30+(total-4)*40;
   else 
      fee=4*30+4*40+(total-8)*60;  
   printf("%d\n",fee);
   return 0;
}