Programa para encontrar el conteo de monedas de cada tipo a partir de la proporción dada

Dada la cantidad total de rupias en una bolsa y la proporción de monedas. La bolsa contiene solo monedas de 1 R, 50 paise, 25 paise en proporción X, Y, Z. La tarea es determinar el número de monedas de 1 Rs, monedas de 50 Paise y monedas de 25 Paise para que después de la suma de todas obtengamos nuevamente el total de rupias dadas.
Ejemplos: 
 

Input: totalRupees = 1800, X = 1, Y = 2, Z = 4
Output:  1 rupees coins = 600
         50 paisa coins = 1200
         25 paisa coins = 2400

Input: totalRupees = 2500, X = 2, Y = 4, Z = 2
Output:  1 rupees coins = 555
         50 paisa coins = 1110
         25 paisa coins = 2220

Acercarse: 
 

Supongamos que la proporción en la que se dividen las monedas de 1 R, 50 paise y 25 paise es 1:2:4. 
Ahora, 
las monedas de 1 R en una bolsa son 1x. 
50 monedas de paise en una bolsa son 2x. 
25 monedas de paise en una bolsa son 4x.
Ahora convierta estos paises en rupias. 
Entonces, 
x monedas de 1 Rs cada una, el valor total es x rupias. 
2x monedas de 50 paise es decir (1/2) rupias cada una, el valor total es x rupias. 
4x monedas de 25 paise es decir (1/4) rupias cada una, el total es x rupias.
Por lo tanto,
3x = 1800 
x = 600
1 moneda de rupias = 600 * 1 = 600 
50 monedas de paisa = 600 * 2 = 1200 
25 monedas de paisa = 600 * 4 = 2400
 

A continuación se muestra la implementación del enfoque anterior: 
 

C++

// C++ implementation of above approach
#include <bits/stdc++.h>
using namespace std;
 
// function to calculate coin.
int coin(int totalRupees, int X, int Y, int Z)
{
 
    float one = 0, fifty = 0, twentyfive = 0,
          result = 0, total = 0;
 
    // Converting each of them in rupees.
    // As we are given totalRupees = 1800
    one = X * 1;
    fifty = ((Y * 1) / 2.0);
    twentyfive = ((Z * 1) / 4.0);
 
    total = one + fifty + twentyfive;
 
    result = ((totalRupees) / total);
 
    return result;
}
 
// Driver code
int main()
{
    int totalRupees = 1800;
    int X = 1, Y = 2, Z = 4;
 
    int Rupees = coin(totalRupees, X, Y, Z);
 
    cout << "1 rupess coins = " << Rupees * 1 << endl;
    cout << "50 paisa coins = " << Rupees * 2 << endl;
    cout << "25 paisa coins = " << Rupees * 4 << endl;
 
    return 0;
}

Java

// Java implementation of above approach
 
import java.io.*;
 
class GFG {
  
// function to calculate coin.
 static int coin(int totalRupees, int X, int Y, int Z)
{
 
    float one = 0, fifty = 0, twentyfive = 0,
        result = 0, total = 0;
 
    // Converting each of them in rupees.
    // As we are given totalRupees = 1800
    one = X * 1;
    fifty = ((Y * 1) / 2);
    twentyfive = ((Z * 1) / 4);
 
    total = one + fifty + twentyfive;
 
    result = ((totalRupees) / total);
 
    return (int)result;
}
 
// Driver code
 
    public static void main (String[] args) {
         
    int totalRupees = 1800;
    int X = 1, Y = 2, Z = 4;
 
    int Rupees = coin(totalRupees, X, Y, Z);
 
    System.out.println( "1 rupess coins = " + Rupees * 1);
    System.out.println( "50 paisa coins = " + Rupees * 2);
    System.out.println( "25 paisa coins = " + Rupees * 4);
    }
}
//This code is contributed by  inder_verma.

Python3

# Python3 implementation of above approach
 
# function to calculate coin.
def coin(totalRupees, X, Y, Z):
 
    # Converting each of them in rupees.
    # As we are given totalRupees = 1800
    one = X * 1
    fifty = ((Y * 1) / 2.0)
    twentyfive = ((Z * 1) / 4.0)
    total = one + fifty + twentyfive
    result = ((totalRupees) / total)
 
    return int(result)
 
# Driver code
if __name__=='__main__':
    totalRupees = 1800
    X, Y, Z = 1, 2, 4
 
    Rupees = coin(totalRupees, X, Y, Z)
 
    print("1 rupess coins = ", Rupees * 1)
    print("50 paisa coins = ", Rupees * 2)
    print("25 paisa coins = ", Rupees * 4)
 
# This code is contributed by
# Sanjit_Prasad

C#

// C# implementation of above approach
using System;
 
class GFG
{
 
// function to calculate coin.
static int coin(int totalRupees, int X,
                int Y, int Z)
{
 
    float one = 0, fifty = 0, twentyfive = 0,
          result = 0, total = 0;
 
    // Converting each of them in rupees.
    // As we are given totalRupees = 1800
    one = X * 1;
    fifty = ((Y * 1) / 2);
    twentyfive = ((Z * 1) / 4);
 
    total = one + fifty + twentyfive;
 
    result = ((totalRupees) / total);
 
    return (int)result;
}
 
// Driver code
public static void Main ()
{
    int totalRupees = 1800;
    int X = 1, Y = 2, Z = 4;
     
    int Rupees = coin(totalRupees, X, Y, Z);
     
    Console.WriteLine( "1 rupess coins = " + Rupees * 1);
    Console.WriteLine( "50 paisa coins = " + Rupees * 2);
    Console.WriteLine( "25 paisa coins = " + Rupees * 4);
}
}
 
// This code is contributed by inder_verma

PHP

<?php
// PHP implementation of above approach
 
//function to calculate coin
function coin($totalRupees, $X, $Y, $Z)
{
    $one = 0;
    $fifty = 0;
    $twentyfive = 0;
    $result = 0;
    $total = 0;
         
    // Converting each of them in rupees.
    // As we are given totalRupees = 1800    
    $one = $X * 1;
    $fifty = (($Y * 1) / 2.0);
    $twentyfive = (($Z * 1) / 4.0);
 
    $total = $one + $fifty + $twentyfive;
 
    $result = (($totalRupees) / $total);
 
    return $result;
     
}
 
// Driver Code
$totalRupees = 1800;
$X = 1;
$Y = 2;
$Z = 4;
$Rupees = coin($totalRupees, $X, $Y, $Z);
echo "1 rupess coins = ", $Rupees * 1, "\n";
echo "50 paisa coins = ", $Rupees * 2, "\n";
echo "25 paisa coins = ", $Rupees * 4, "\n";
 
// This code is contributed
// by Shashank_Sharma.
?>

Javascript

<script>
 
// Javascript implementation of above approach
 
// function to calculate coin.
function coin(totalRupees, X, Y, Z)
{
 
    var one = 0, fifty = 0, twentyfive = 0,
        result = 0, total = 0;
 
    // Converting each of them in rupees.
    // As we are given totalRupees = 1800
    one = X * 1;
    fifty = ((Y * 1) / 2.0);
    twentyfive = ((Z * 1) / 4.0);
 
    total = one + fifty + twentyfive;
 
    result = ((totalRupees) / total);
 
    return result;
}
 
// Driver code
var totalRupees = 1800;
var X = 1, Y = 2, Z = 4;
var Rupees = coin(totalRupees, X, Y, Z);
document.write( "1 rupess coins = " + Rupees * 1 + "<br>");
document.write( "50 paisa coins = " + Rupees * 2 + "<br>");
document.write( "25 paisa coins = " + Rupees * 4 + "<br>");
 
</script>
Producción: 

1 rupess coins = 600
50 paisa coins = 1200
25 paisa coins = 2400

 

Complejidad del tiempo:O(1)
Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por Naman_Garg y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *