2017年9月17日 星期日

[C_MM13-易] 停車費計算(C++)

[C_MM13-易] 停車費計算

  1. #include<iostream>  
  2. #include<iomanip>  
  3. #include <math.h>  
  4. using namespace std;  
  5.   
  6. int main() {  
  7.     int start_hr, start_min, end_hr, end_min, sum_time, money;  
  8.     while(cin >> start_hr >> start_min && cin >> end_hr >> end_min)  
  9.     {  
  10.         if((0 <= start_hr && start_hr <= 23) && (0 <= end_hr && end_hr <= 23))  
  11.         {  
  12.             if((0 <= start_min && start_min <= 59) && (0 <= end_min && end_min <= 59))  
  13.             {  
  14.                 sum_time = (end_hr-start_hr)*60 + (end_min - start_min);  
  15.                 if(sum_time <= 120)  
  16.                 {  
  17.                     money = (floor(sum_time/30))*30;  
  18.                     cout << money << endl;  
  19.                 }  
  20.                 else if(240 >=sum_time && sum_time > 120)  
  21.                 {  
  22.                     money = 4*30+(floor((sum_time-120)/30))*40;  
  23.                     cout << money << endl;  
  24.                 }  
  25.                 else if(240 < sum_time)  
  26.                 {  
  27.                     money = 4*30 + 4*40 + (floor((sum_time-240)/30))*60;  
  28.                     cout << money << endl;  
  29.                 }  
  30.             }  
  31.         }  
  32.     }  
  33.     return 0;  
  34. }  


沒有留言:

張貼留言