📌  相关文章
📜  行驶给定小时数后要支付的总金额

📅  最后修改于: 2021-04-26 05:12:14             🧑  作者: Mango

给定出租车的出行成本,每小时头n小时为m卢比,然后为每小时x卢比,给定总的出行时间以分钟为单位,那么任务就是找到总成本。

注意:如果开始一个小时,则旅行者必须支付该小时的全部费用。

例子:

Input:  m = 50, n = 5, x = 67, mins 2927
Output: 3198
m = 50, n = 5, x = 67, Minutes travelled = 2927
Thus hours travelled = 49
Thus cost = 5 * 50 + (49-5) * 67 = 2927

Input: m = 50, n = 40, x = 3, mins = 35
Output: 50

方法:首先,以(旅行的分钟数)/ 60为上限来计算旅行的小时数,就好像我们开始一个小时一样,我们必须支付一整小时的价格。然后我们看到,如果计算出的小时数小于或等于n,则直接给出答案,因为m *经过的小时数,否则答案为n * m +(hourscalculated – n)* x

下面是上述方法的实现:

C++
// CPP implementation of the above approach
#include 
using namespace std;
  
int main(){
  
    float m=50, n=5, x=67, h=2927;
  
    // calculating hours travelled
    int z = (ceil(h / 60*1.0));
    if(z <= n)
        cout<


Java
// Java implementation of the above approach
  
import java.io.*;
  
class GFG {
      
  
    public static void main (String[] args) {
            float m=50, n=5, x=67, h=2927;
  
    // calculating hours travelled
    int z = (int)(Math.ceil(h / 60*1.0));
    if(z <= n)
        System.out.println(z * m);
    else
        System.out.println(n * m+(z-n)*x);
    }
}
  
// This code is contributed by shs


Python3
# Python3 implementation of the above approach
  
import math as ma
m, n, x, h = 50, 5, 67, 2927
  
# calculating hours travelled
z = int(ma.ceil(h / 60)) 
if(z <= n):
    print(z * m)
else:
    print(n * m+(z-n)*x)


C#
// C# implementation of the above approach
  
using System;
  
class GFG {
      
  
    public static void Main () {
            float m=50, n=5, x=67, h=2927;
  
    // calculating hours travelled
    int z = (int)(Math.Ceiling((h / 60*1.0)));
    if(z <= n)
      Console.WriteLine(z * m);
    else
        Console.WriteLine(n * m+(z-n)*x);
    }
}
  
// This code is contributed by anuj_67..


PHP


输出:
3198