📌  相关文章
📜  每小时停车所花费的时间

📅  最后修改于: 2021-04-22 08:08:18             🧑  作者: Mango

汽车行驶时的平均速度为S km / h,没有任何停车,停车时汽车的速度降低为平均S1 km / h。任务是查找每小时因浪费而浪费的时间。
例子:

方法:以第一个示例为例,

可以使用以下公式计算得出:

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to return the time taken
// per hour for stoppage
int numberOfMinutes(int S, int S1)
{
 
    int Min = 0;
 
    Min = ((S - S1) / floor(S)) * 60;
 
    return Min;
}
 
// Driver code
int main()
{
    int S = 30, S1 = 10;
 
    cout << numberOfMinutes(S, S1) << " min";
 
    return 0;
}


Java
// Java implementation of the approach
import java.util.*;
 
class GFG
{
 
// Function to return the time taken
// per hour for stoppage
static int numberOfMinutes(int S, int S1)
{
    int Min = 0;
 
    Min = (int) (((S - S1) / Math.floor(S)) * 60);
 
    return Min;
}
 
// Driver code
public static void main(String[] args)
{
    int S = 30, S1 = 10;
 
    System.out.println(numberOfMinutes(S, S1) + " min");
}
}
 
// This code is contributed by Princi Singh


Python3
# Python3 implementation of the approach
import math
 
# Function to return the time taken
# per hour for stoppage
def numberOfMinutes(S, S1):
 
    Min = 0;
 
    Min = ((S - S1) / math.floor(S)) * 60;
 
    return int(Min);
 
# Driver code
if __name__ == '__main__':
    S, S1 = 30, 10;
 
    print(numberOfMinutes(S, S1), "min");
 
# This code is contributed by Rajput-Ji


C#
// C# implementation of the approach
using System;
 
class GFG
{
 
// Function to return the time taken
// per hour for stoppage
static int numberOfMinutes(int S, int S1)
{
    int Min = 0;
 
    Min = (int) (((S - S1) /
                   Math.Floor((double)S)) * 60);
 
    return Min;
}
 
// Driver code
public static void Main()
{
    int S = 30, S1 = 10;
 
    Console.WriteLine(numberOfMinutes(S, S1) +
                                      " min");
}
}
 
// This code is contributed
// by Akanksha Rai


Javascript


输出:
40 min