给定水箱的容积V (以升为单位)。有一个泵以每分钟M升的速度向油箱加油。水箱底部有泄漏,以每分钟N升的速度浪费水。给定N小于M。任务是计算如果在装满水箱后看到泄漏,将浪费多少水。
例子:
Input : V = 700, M = 10, N = 3
Output : 300
Input : V = 1000, M = 100, N = 50
Output : 1000
方法:给定加油泵的速度为每分钟M升。因此,一分钟内充满的水量为M升。而且,一分钟内会浪费掉N升的水。因此,一分钟后,水箱中的水量将为(M – N)。因此,将油箱充满泄漏所需的总时间为V /(MN)。
因此,浪费的水量为(V /(MN))*N。
下面是上述方法的实现:
C++
// C++ program to find the volume of water wasted
#include
using namespace std;
// Function to calculate amount of wasted water
double wastedWater(double V, double M, double N)
{
double wasted_amt, amt_per_min, time_to_fill;
// filled amount of water in one minute
amt_per_min = M - N;
// total time taken to fill the tank
// because of leakage
time_to_fill = V / amt_per_min;
// wasted amount of water
wasted_amt = N * time_to_fill;
return wasted_amt;
}
// Driver code
int main()
{
double V, M, N;
V = 700;
M = 10;
N = 3;
cout << wastedWater(V, M, N) << endl;
V = 1000;
M = 100;
N = 50;
cout << wastedWater(V, M, N) << endl;
return 0;
}
Java
// Java program to find the
// volume of water wasted
class GFG
{
// Function to calculate amount of wasted water
static double wastedWater(double V, double M, double N)
{
double wasted_amt, amt_per_min, time_to_fill;
// filled amount of water in one minute
amt_per_min = M - N;
// total time taken to fill the tank
// because of leakage
time_to_fill = V / amt_per_min;
// wasted amount of water
wasted_amt = N * time_to_fill;
return wasted_amt;
}
// Driver code
public static void main(String[] args)
{
double V, M, N;
V = 700;
M = 10;
N = 3;
System.out.println(wastedWater(V, M, N)) ;
V = 1000;
M = 100;
N = 50;
System.out.println(wastedWater(V, M, N));
}
}
// This Code is Contributed by Code_Mech.
Python3
# Python3 program to find the volume
# of water wasted
# Function to calculate amount
# of wasted water
def wastedWater(V, M, N):
# filled amount of water in one minute
amt_per_min = M - N
# total time taken to fill the tank
# because of leakage
time_to_fill = V / amt_per_min
# wasted amount of water
wasted_amt = N * time_to_fill
return wasted_amt
# Driver code
V = 700
M = 10
N = 3
print(wastedWater(V, M, N))
V = 1000
M = 100
N = 50
print(wastedWater(V, M, N))
# This code is contributed by Shrikant13
C#
// C# program to find the
// volume of water wasted
using System;
class GFG
{
// Function to calculate amount of wasted water
static double wastedWater(double V, double M, double N)
{
double wasted_amt, amt_per_min, time_to_fill;
// filled amount of water in one minute
amt_per_min = M - N;
// total time taken to fill the tank
// because of leakage
time_to_fill = V / amt_per_min;
// wasted amount of water
wasted_amt = N * time_to_fill;
return wasted_amt;
}
// Driver code
public static void Main()
{
double V, M, N;
V = 700;
M = 10;
N = 3;
Console.WriteLine(wastedWater(V, M, N)) ;
V = 1000;
M = 100;
N = 50;
Console.WriteLine(wastedWater(V, M, N));
}
}
// This Code is Contributed by ihritik
PHP
输出:
300
1000