-4
Read a floating point value to two decimal places. This value represents a monetary value. Then calculate the fewest possible banknotes and coins in which the value can be broken down. The banknotes considered are 100, 50, 20, 10, 5, 2. The possible currencies are 1, 0.50, 0.25, 0.10, 0.05 and 0.01. Show below the list of notes required.
Entree:
- The input file contains a floating point value N (0 N 1000000.00).
Exit:
- Print the minimum amount of banknotes and coins needed to exchange the initial amount, as per example provided.
Note: Use a dot (
.
) to separate the decimal part.
using System;
namespace URI_1021_notas_e_moedas
{
class Program
{
static void Main(string[] args)
{
double N;
int n100, n50, n20, n10, n5, n2, m100, m50, m25, m10, m5, m1, resto;
N = double.Parse(Console.ReadLine());
resto = (int)N; // não tem conversão de double para int; então tem que fazer esse truque
Console.WriteLine("NOTAS:");
n100 = resto / 10000;
Console.WriteLine(n100 + " nota(s) de R$ 100.00");
resto = resto % 10000;
n50 = resto / 5000;
Console.WriteLine(n50 + " nota(s) de R$ 50.00");
resto = resto % 5000;
n20 = resto / 2000;
Console.WriteLine(n20 + " nota(s) de R$ 20.00");
resto = resto % 2000;
n10 = resto / 1000;
Console.WriteLine(n10 + " nota(s) de R$ 10.00");
resto = resto % 1000;
n5 = resto / 500;
Console.WriteLine(n5 + " nota(s) de R$ 5.00");
resto = resto % 500;
n2 = resto / 200;
Console.WriteLine(n2 + " nota(s) de R$ 2.00");
Console.WriteLine("MOEDAS:");
resto = resto % 200;
m100 = resto / 100;
Console.WriteLine(m100 + " moeda(s) de R$ 1.00");
resto = resto % 100;
m50 = resto / 50;
Console.WriteLine(m50 + " moeda(s) de R$ 0.50");
resto = resto % 50;
m25 = resto / 25;
Console.WriteLine(m25 + " moeda(s) de R$ 0.25");
resto = resto % 25;
m10 = resto / 10;
Console.WriteLine(m10 + " moeda(s) de R$ 0.10");
resto = resto % 10;
m5 = resto / 5;
Console.WriteLine(m5 + " moeda(s) de R$ 0.05");
resto = resto % 5;
m1 = resto;
Console.WriteLine(m1 + " moeda(s) de R$ 0.01");
Console.ReadLine();
}
}
}
play your way out here, see if it’s the same as the Uri website
– Gabriella Selbach
I sent it again and the exit looks exactly like the URI... I don’t know what’s going on... thank you very much, Gabriella
– Jairo Garcia Pereira
worked? You’re welcome =D
– Gabriella Selbach
@Jairogarciapereira Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already done so. You would help the community by identifying the best solution).
– Maniero