URI - BEECROWD - BEE 1021 | Banknotes and Coins Solution in C,C++,Python

URI - BEECROWD - BEE Online Judge Solution  1021 | Banknotes and Coins - URI - BEECROWD - BEE 1021 Solution in C,C++,Python

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 SampleOutput 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

URI Online Judge Solution  1021 | Banknotes and Coins - URI 1021 Solution in C,C++,Python:


  URI Problem 1021 Solution in C :   

  URI Online Judge 1021 Solve  in C :                                                                             
#include <stdio.h>
 
int main()
 
{
 
    double n, d[] = {100.0, 50.0, 20.0, 10.0, 5.0, 2.0, 1.0, 0.5, 0.25, 0.10, 0.05, 0.01};
 
    int t = 0, c;
 
    scanf("%lf", &n);
 
    printf("NOTAS:\n");
 
    t = 0;
 
    n+=1e-9;
 
    while (d[t] >= 0.01)
 
    {
 
        c = 0;
 
        while (n >= d[t])
 
        {
 
            n -= d[t];
 
            c++;
 
        }
 
        if (d[t] == 1.0)
 
            printf("MOEDAS:\n");
 
        if (d[t] >= 2.0 )
 
            printf("%d nota(s) de R$ %.2f\n", c, d[t]);
 
        else
 
            printf("%d moeda(s) de R$ %.2f\n", c, d[t]);
 
        t++;
 
    }
 
    return 0;
 
}

9 Responses to URI - BEECROWD - BEE 1021 | Banknotes and Coins Solution in C,C++,Python

  1. In the number 1e-9, the numbers are defined as follows:

    1 = coefficient
    e = 10 to the power of
    -9 = exponent

    The scientific notation 1e-9 is same as 1 x 10^-9 or 1 x 10-9. Thus, to get the answer to 1e-9 as a decimal, we multiply 1 by 10 to the power of -9.

    = 1e-9
    = 1 × 10-9
    = 0.000000001

    Therefore, 1e-9 number on calculator means or 1e-9 in decimal form is:

    0.000000001

    ReplyDelete
  2. In this line of code, the variable "n" is being incremented by 1e-9.

    1e-9 is scientific notation for 1 * 10^-9, which is a very small decimal number, equivalent to 0.000000001.

    So, this line of code is adding a very small value to the variable "n". Depending on the initial value of "n" and the context in which this line of code is used, this increment may or may not have a significant impact on the overall program behavior.

    ReplyDelete
  3. anyone knows whats wrong with my code? Beecrowd always returns me wrong answer (0%)

    dinero = float(input())
    print('NOTAS:\n{} nota(s) de R$ 100.00'.format(int(dinero / 100)))
    aux = dinero % 100
    print('{} nota(s) de R$ 50.00'.format(int(aux / 50)))
    aux = aux % 50
    print('{} nota(s) de R$ 20.00'.format(int(aux / 20)))
    aux = aux % 20
    print('{} nota(s) de R$ 10.00'.format(int(aux / 10)))
    aux = aux % 10
    print('{} nota(s) de R$ 5.00'.format(int(aux / 5)))
    aux = aux % 5
    print('{} nota(s) de R$ 2.00'.format(int(aux / 2)))
    aux = aux % 2
    print('MOEDAS:\n{} moeda(s) de R$ 1.00'.format(int(aux / 1)))
    aux = float(aux % 1)
    print('{} moeda(s) de R$ 0.50'.format(int(aux / 0.5)))
    aux = float(aux % 0.5)
    print('{} moeda(s) de R$ 0.25'.format(int(aux / 0.25)))
    aux = float(aux % 0.25)
    print('{} moeda(s) de R$ 0.10'.format(int(aux / 0.1)))
    aux = float(aux % 0.1)
    print('{} moeda(s) de R$ 0.05'.format(int(aux / 0.05)))
    aux = float(aux % 0.05)
    print('{} moeda(s) de R$ 0.01'.format(int(aux / 0.01)))
    aux = float(aux % 0.01)

    ReplyDelete
  4. use meaningful word instead of using a, b, c, t or like this.

    ReplyDelete