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
Delete