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
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 |
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;
}
URI Problem 1021 Solution in C ++:
URI Online Judge 1021 Solve in C++ : |
#include <iostream>
using namespace std;
int main(){
double N;
int inteiro, aux, aux1;
while(cin >> N){
inteiro = N;
N = 100*N;
aux1 = N;
cout << "NOTAS:\n";
cout << inteiro/100 << " nota(s) de R$ 100.00\n";
aux = (inteiro%100);
cout << aux/50 << " nota(s) de R$ 50.00\n";
aux = (aux%50);
cout << aux/20 << " nota(s) de R$ 20.00\n";
aux = (aux%20);
cout << aux/10 << " nota(s) de R$ 10.00\n";
aux = (aux%10);
cout << aux/5 << " nota(s) de R$ 5.00\n";
aux = (aux%5);
cout << aux/2 << " nota(s) de R$ 2.00\n";
aux = (aux%2);
cout << "MOEDAS:\n";
cout << aux/1 << " moeda(s) de R$ 1.00\n";
aux1 = aux1%100;
cout << aux1/50 << " moeda(s) de R$ 0.50\n";
aux1 = aux1%50;
cout << aux1/25 << " moeda(s) de R$ 0.25\n";
aux1 = aux1%25;
cout << aux1/10 << " moeda(s) de R$ 0.10\n";
aux1 = aux1%10;
cout << aux1/5 << " moeda(s) de R$ 0.05\n";
aux1 = aux1%5;
cout << aux1/1 << " moeda(s) de R$ 0.01\n";
}
return 0;
}
URI Problem 1021 Solution in Python:
URI Online Judge 1021 Solve in Python : |
A=float(input())
N=A
a=N/100
b=N%100
c=b/50
d=b%50
e=d/20
f=d%20
g=f/10
h=f%10
i=h/5
j=h%5
k=j/2
l=j%2
E=A*100
B=(int(E))
m=B%100
n=m/50
o=m%50
p=o/25
q=o%25
r=q/10
s=q%10
t=s/5
u=s%5
print("NOTAS:")
print(f"{int(a)} nota(s) de R$ 100.00")
print(f"{int(c)} nota(s) de R$ 50.00")
print(f"{int(e)} nota(s) de R$ 20.00")
print(f"{int(g)} nota(s) de R$ 10.00")
print(f"{int(i)} nota(s) de R$ 5.00")
print(f"{int(k)} nota(s) de R$ 2.00")
print(f"MOEDAS:")
print(f"{int(l)} moeda(s) de R$ 1.00")
print(f"{int(n)} moeda(s) de R$ 0.50")
print(f"{int(p)} moeda(s) de R$ 0.25")
print(f"{int(r)} moeda(s) de R$ 0.10")
print(f"{int(t)} moeda(s) de R$ 0.05")
print(f"{int(u)} moeda(s) de R$ 0.01")
Previous Post:
Good Job
ReplyDeleteThank you
DeleteWhy did you put 1e+9?
ReplyDeleteIn the number 1e-9, the numbers are defined as follows:
ReplyDelete1 = 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
thank you
ReplyDeleteIn this line of code, the variable "n" is being incremented by 1e-9.
ReplyDelete1e-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.
anyone knows whats wrong with my code? Beecrowd always returns me wrong answer (0%)
ReplyDeletedinero = 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)
use meaningful word instead of using a, b, c, t or like this.
ReplyDeleteThank you for good suggestions
Delete