Dado el volumen V de un tanque en litros. Hay una bomba que está llenando el tanque a una velocidad de M litros por minuto. Hay una fuga en el fondo del tanque que desperdicia agua a una velocidad de N litros por minuto. Dado que N es menor que M. La tarea es calcular la cantidad de agua que se desperdiciará si se observa una fuga después de llenar el tanque por completo.
Ejemplos:
Input : V = 700, M = 10, N = 3 Output : 300 Input : V = 1000, M = 100, N = 50 Output : 1000
Planteamiento: Dado que la velocidad de llenado de la bomba es de M litros por minuto. Entonces, la cantidad de agua llena en un minuto es M Litro. Además, se desperdician N litros de agua en un minuto. Por lo tanto, después de un minuto, la cantidad de agua en el tanque será (M – N). Por lo tanto, el tiempo total necesario para llenar el tanque con fugas será V / (MN).
Por lo tanto, la cantidad de agua desperdiciada será (V / (MN)) * N.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to find the volume of water wasted #include <iostream> 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
<?php // PHP program to find the // volume of water wasted // Function to calculate amount of wasted water function 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; echo wastedWater($V, $M, $N), "\n"; $V = 1000; $M = 100; $N = 50; echo wastedWater($V, $M, $N); // This Code is Contributed by ihritik ?>
Javascript
<script> // Javascript program to find the // volume of water wasted // Function to calculate amount of wasted water function wastedWater(V, M, N) { let 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 program let V, M, N; V = 700; M = 10; N = 3; document.write(wastedWater(V, M, N), "<br>") ; V = 1000; M = 100; N = 50; document.write(wastedWater(V, M, N)); </script>
300 1000
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por Vivek.Pandit y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA