Algorithm


Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1021

Problem Details - 

URI Online Judge | 1021

Banknotes and Coins

By Neilor Tonin, URI  Brazil

Timelimit: 1

Read a value of floating point with two decimal places. This represents a monetary value. After this, calculate the smallest possible number of notes and coins on which the value can be decomposed. The considered notes are of 100, 50, 20, 10, 5, 2. The possible coins are of 1, 0.50, 0.25, 0.10, 0.05 and 0.01. Print the message “NOTAS:” followed by the list of notes and the message “MOEDAS:” followed by the list of coins.

Input

The input file contains a value of floating point (0 ≤ ≤ 1000000.00).

Output

Print the minimum quantity of banknotes and coins necessary to change the initial value, as the given example.

 
Input Sample Output Sample

576.73

NOTAS:
5 nota(s) de R$ 100.00
1 nota(s) de R$ 50.00
1 nota(s) de R$ 20.00
0 nota(s) de R$ 10.00
1 nota(s) de R$ 5.00
0 nota(s) de R$ 2.00
MOEDAS:
1 moeda(s) de R$ 1.00
1 moeda(s) de R$ 0.50
0 moeda(s) de R$ 0.25
2 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
3 moeda(s) de R$ 0.01

4.00

NOTAS:
0 nota(s) de R$ 100.00
0 nota(s) de R$ 50.00
0 nota(s) de R$ 20.00
0 nota(s) de R$ 10.00
0 nota(s) de R$ 5.00
2 nota(s) de R$ 2.00
MOEDAS:
0 moeda(s) de R$ 1.00
0 moeda(s) de R$ 0.50
0 moeda(s) de R$ 0.25
0 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
0 moeda(s) de R$ 0.01

91.01

NOTAS:
0 nota(s) de R$ 100.00
1 nota(s) de R$ 50.00
2 nota(s) de R$ 20.00
0 nota(s) de R$ 10.00
0 nota(s) de R$ 5.00
0 nota(s) de R$ 2.00
MOEDAS:
1 moeda(s) de R$ 1.00
0 moeda(s) de R$ 0.50
0 moeda(s) de R$ 0.25
0 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
1 moeda(s) de R$ 0.01

 

Code Examples

#1 Code Example with C Programming

Code - C Programming

#include <stdio.h>

int main() {
    int n100, n50, n20, n10, n5, n2;
    int m1, m50, m25, m10, m05, m01;
    double n;

    scanf("%lf", &n);
    int notas = n;
    int moedas = (n - notas) * 100;

    if( (moedas * 1000) % 10 == 9) {
        moedas++;
    }


    n100 = notas/100;
    notas = notas%100;
    n50 = notas/50;
    notas = notas%50;
    n20 = notas/20;
    notas = notas%20;
    n10 = notas/10;
    notas = notas%10;
    n5 = notas/5;
    notas = notas%5;
    n2 = notas/2;
    notas = notas%2;

    m1 = notas/1;
    notas = notas%1;
    m50 = moedas/50;
    moedas = moedas%50;
    m25 = moedas/25;
    moedas = moedas%25;
    m10 = moedas/10;
    moedas = moedas%10;
    m05 = moedas/5;
    moedas = moedas%5;
    m01 = moedas/1;

    printf("NOTAS:\n");

    printf("%d nota(s) de R$ 100.00\n", n100);
    printf("%d nota(s) de R$ 50.00\n", n50);
    printf("%d nota(s) de R$ 20.00\n", n20);
    printf("%d nota(s) de R$ 10.00\n", n10);
    printf("%d nota(s) de R$ 5.00\n", n5);
    printf("%d nota(s) de R$ 2.00\n", n2);

    printf("MOEDAS:\n");

    printf("%d moeda(s) de R$ 1.00\n", m1);
    printf("%d moeda(s) de R$ 0.50\n", m50);
    printf("%d moeda(s) de R$ 0.25\n", m25);
    printf("%d moeda(s) de R$ 0.10\n", m10);
    printf("%d moeda(s) de R$ 0.05\n", m05);
    printf("%d moeda(s) de R$ 0.01\n", m01);

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
576.73

#2 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
using namespace std;

int main() {
    double n100, n50, n20, n10, n5, n2;
    double m1, m50, m25, m10, m05, m01;
    double n;

    cin >> n;
    int notas = n;
    int moedas = (n - notas) * 100;

    if((moedas * 1000) % 10 == 9){
        moedas++;
    }


    n100 = notas/100;
    notas = notas%100;
    n50 = notas/50;
    notas = notas%50;
    n20 = notas/20;
    notas = notas%20;
    n10 = notas/10;
    notas = notas%10;
    n5 = notas/5;
    notas = notas%5;
    n2 = notas/2;
    notas = notas%2;

    m1 = notas/1;
    notas = notas%1;
    m50 = moedas/50;
    moedas = moedas%50;
    m25 = moedas/25;
    moedas = moedas%25;
    m10 = moedas/10;
    moedas = moedas%10;
    m05 = moedas/5;
    moedas = moedas%5;
    m01 = moedas/1;

    cout << "NOTAS:" << endl; 
    cout << n100 << " nota(s) de R$ 100.00" << endl;
    cout << n50 << " nota(s) de R$ 50.00" << endl;
    cout << n20 << " nota(s) de R$ 20.00" << endl;
    cout << n10 << " nota(s) de R$ 10.00" << endl;
    cout << n5 << " nota(s) de R$ 5.00" << endl;
    cout << n2 << " nota(s) de R$ 2.00" << endl;
    cout << "MOEDAS:" << endl;
    cout << m1 << " moeda(s) de R$ 1.00" << endl;
    cout << m50 << " moeda(s) de R$ 0.50" << endl;
    cout << m25 << " moeda(s) de R$ 0.25" << endl;
    cout << m10 << " moeda(s) de R$ 0.10" << endl;
    cout << m05 << " moeda(s) de R$ 0.05" << endl;
    cout << m01 << " moeda(s) de R$ 0.01" << endl;

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4.00

#3 Code Example with Java Programming

Code - Java Programming

import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        float x;
        int note100,note50,note20,note10,note5,note2;
        int moeda1,moeda5,moeda25,moeda10,moeda05,moeda01;
        int reminder100;
        Scanner input=new Scanner(System.in);
        x = input.nextFloat();
        note100 =(int) x / 100;
        reminder100 = (int) (x % 100);
        note50 = (reminder100) / 50;
        note20 = (reminder100 % 50 )/ 20;
        note10 = ((reminder100 % 50 )% 20) / 10;
        note5 = (((reminder100 % 50 )% 20) % 10) / 5;
        note2 = (((reminder100 % 50 )% 20) % 5) / 2;

        //------     MOEDAS:    ------------//
        moeda1 =  (((((reminder100 % 50 )% 20) % 5) % 2) / 1);
        float reminderMoeda = (float) (((((reminder100 % 50 )% 20) % 5) % 2));

        float meda5Float = (float) ((reminderMoeda % 1) / .5);
        moeda5 = (int) (meda5Float);

        moeda25 = (int) (((((((reminder100 % 50 )% 20) % 5) % 2) % 1) % .5) / .25);
        moeda10 = (int) ((((((((reminder100 % 50 )% 20) % 5) % 2) % 1) % .5) % .25) / .1);
        moeda05 = (int) (((((((((reminder100 % 50 )% 20) % 5) % 2) % 1) % .5) % .25) % .1) / .05);
        moeda01 = (int) ((((((((((reminder100 % 50 )% 20) % 5) % 2) % 1) % .5) % .25) % .1) % .05) / .01);


        System.out.print("NOTAS:\n");
        System.out.print(note100 +" nota(s) de R$ 100.00\n");
        System.out.print(note50 +" nota(s) de R$ 50.00\n");
        System.out.print(note20 +" nota(s) de R$ 20.00\n");
        System.out.print(note10 +" nota(s) de R$ 10.00\n");
        System.out.print(note5 +" nota(s) de R$ 5.00\n");
        System.out.print(note2 +" nota(s) de R$ 2.00\n\n");

        System.out.print("MOEDAS:\n");
        System.out.print(moeda1 +" moeda(s) de R$ 1.00\n");
        System.out.print(meda5Float +" moeda(s) de R$ 0.50\n");
        System.out.print(moeda25 +" moeda(s) de R$ 0.25\n");
        System.out.print(moeda10 +" moeda(s) de R$ 0.10\n");
        System.out.print(moeda05 +" moeda(s) de R$ 0.05\n");
        System.out.print(moeda01 +" moeda(s) de R$ 0.01\n");

    }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
91.01

#4 Code Example with Python Programming

Code - Python Programming

value = eval(input());

cem = cinquenta = vinte = dez = cinco = dois = um = 0;
cincents = vintecincents = dezcents = cincocents = cents = 0;

value = float("%.2f" % value)
if int(value/100) >= 1:
 cem = int(value/100);
 value -= cem*100;

value = float("%.2f" % value)
if int(value/50) >= 1:
 cinquenta = int(value/50);
 value -= cinquenta*50;

value = float("%.2f" % value)
if int(value/20) >= 1:
 vinte = int(value/20.00);
 value -= vinte*20;

value = float("%.2f" % value)
if int(value/10) >= 1:
 dez = int(value/10);
 value -= dez*10.00;

value = float("%.2f" % value)
if int(value/5) >= 1:
 cinco = int(value/5);
 value -= cinco*5;

value = float("%.2f" % value)
if int(value/2) >= 1:
 dois = int(value/2);
 value -= dois*2;

value = float("%.2f" % value)
if int(value/1) >= 1:
 um = int(value/1);
 value -= um*1;

value = float("%.2f" % value)
if int(value/0.50) >= 1:
 cincents = int(value/0.50);
 value -= cincents*0.50;

value = float("%.2f" % value)
if int(value/0.25) >= 1:
 vintecincents = int(value/0.25);
 value -= vintecincents*0.25;

value = float("%.2f" % value)
if int(value/0.10) >= 1:
 dezcents = int(value/0.10);
 value -= dezcents*0.10;

value = float("%.2f" % value)
if int(value/0.05) >= 1:
 cincocents = int(value/0.05);
 value -= cincocents*0.05;

value = float("%.2f" % value)
if int(value/0.01) >= 0.998:
 cents = int(value/0.01);
 value -= cents*0.01;

print("NOTAS:");
print("%d nota(s) de R$ 100.00" % cem);
print("%d nota(s) de R$ 50.00" % cinquenta);
print("%d nota(s) de R$ 20.00" % vinte);
print("%d nota(s) de R$ 10.00" % dez);
print("%d nota(s) de R$ 5.00" % cinco);
print("%d nota(s) de R$ 2.00" % dois);

print("MOEDAS:");
print("%d moeda(s) de R$ 1.00" % um);
print("%d moeda(s) de R$ 0.50" % cincents);
print("%d moeda(s) de R$ 0.25" % vintecincents);
print("%d moeda(s) de R$ 0.10" % dezcents);
print("%d moeda(s) de R$ 0.05" % cincocents);
print("%d moeda(s) de R$ 0.01" % cents);
Copy The Code & Try With Live Editor

Input

x
+
cmd
4.00
Advertisements

Demonstration


Previous
#1020 Beecrowd Online Judge Solution 1020 Age in Days Solution in C, C++, Java, Python and C#
Next
#1022 Beecrowd Online Judge Solution 1022 TDA Rational Solution in C, C++, Java, Python and C#