URI Online Judge | 1021 Banknotes and Coins (Solution)
Problem Link:
https://www.urionlinejudge.com.br/judge/en/problems/view/1021
Solution:
https://www.urionlinejudge.com.br/judge/en/problems/view/1021
URI Online Judge | 1021
Banknotes and Coins
By Neilor Tonin, URI Brazil
Timelimit: 1
Read a floating point value with two decimal places. This represents a monetary value. Next, calculate the fewest possible notes and coins in 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 contain float point number N (0 ≤ N ≤ 1000000.00).
Output
Print the minimum quantity of banknotes and coins necessary to change the initial value, like as the given example.
Sample Input | Sample Output |
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 |
#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;
}
hey, i'm your fan ;)
ReplyDeleteBoa noite parabens pelo trabalho..so uma sugestao seria possivel voce comentar os codigos de maneira explicativa por gentileza
ReplyDeleteThis comment has been removed by the author.
ReplyDeletewhy it doesn't work in the first one :/
ReplyDelete#include
using namespace std;
int hund,fif,twent,ten,five,two,one;
int num1,hund1,fif1,twent1,ten1,five1;
float num;
int main()
{
scanf("%f",&num);
while(num-100>=0){
num-=100;
hund++;
}
while(num-50>=0){
num-=50;
fif++;
}
while(num-20>=0){
num-=20;
twent++;
}
while(num-10>=0){
num-=10;
ten++;
}
while(num-5>=0){
num-=5;
five++;
}
while(num-2>=0){
num-=2;
two++;
}
while(num-1>=0){
num-=1;
one++;
}
while(num-0.50>=0){
num-=0.50;
hund1++;
}
while(num-0.25>=0){
num-=0.25;
fif1++;
}
while(num-0.10>=0){
num-=0.10;
twent1++;
}
while(num-0.05>=0){
num-=0.05;
ten1++;
}
while(num-0.01>=0){
num-=0.01;
five1++;
}
printf("NOTAS:\n");
printf("%d nota(s) de R$ 100.00\n",hund);
printf("%d nota(s) de R$ 50.00\n",fif);
printf("%d nota(s) de R$ 20.00\n",twent);
printf("%d nota(s) de R$ 10.00\n",ten);
printf("%d nota(s) de R$ 5.00\n",five);
printf("%d nota(s) de R$ 2.00\n",two);
printf("MOEDAS:\n");
printf("%d moeda(s) de R$ 1.00\n",one);
printf("%d moeda(s) de R$ 0.50\n",hund1);
printf("%d moeda(s) de R$ 0.25\n",fif1);
printf("%d moeda(s) de R$ 0.10\n",twent1);
printf("%d moeda(s) de R$ 0.05\n",ten1);
printf("%d moeda(s) de R$ 0.01\n",five1);
return 0;
}
Why my code is wrong for 1021 problem.....my code is..
ReplyDelete#include
int main ()
{
double a;
int b;
scanf(" %lf", &a);
printf("NOTAS:\n");
b = a / 100;
printf("%d nota(s) de R$ 100.00\n", b);
a = a - ( b * 100);
b = a / 50;
printf("%d nota(s) de R$ 50.00\n", b);
a = a - ( b * 50);
b = a / 20;
printf("%d nota(s) de R$ 20.00\n", b);
a = a - ( b * 20);
b = a / 10;
printf("%d nota(s) de R$ 10.00\n", b);
a = a - ( b * 10);
b = a / 5;
printf("%d nota(s) de R$ 5.00\n", b);
a = a - ( b * 5);
b = a / 2;
printf("%d nota(s) de R$ 2.00\n", b);
a = a - ( b * 2);
printf("MOEDAS:\n");
b = a / 1;
printf("%d moeda(s) de R$ 1.00\n", b);
a = a - ( b * 1);
b = a / .50;
printf("%d moeda(s) de R$ 0.50\n", b);
a = a - ( b * .50);
b = a / .25;
printf("%d moeda(s) de R$ 0.25\n", b);
a = a - ( b * .25);
b = a / .10;
printf("%d moeda(s) de R$ 0.10\n", b);
a = a - ( b * .10);
b = a / .05;
printf("%d moeda(s) de R$ 0.05\n", b);
a = a - ( b * .05);
b = a / .01;
printf("%d moeda(s) de R$ 0.01\n", b);
return 0;
}
n+=1e-9;
ReplyDelete"1e-9" what do u mean by that??
that is exponent float declaration. Here base 10 is replaced by e Or E. we can write 1.2*10^-3 as 1.2e-3...
DeleteWhy this is not accepting in JAVA? Showing 10% error.
ReplyDeleteimport java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
double N,rn,j;
int n100=0,n50=0,n20=0,n10=0,n5=0,n2=0,p1=0,p50=0,p25=0,p10=0,p5=0,p01=0;
N=sc.nextDouble();
if (0<=N && N<= 1000000.00){
j=N/100;
n100=(int) j;
rn=N%100;
j=rn/50;
n50=(int) j;
rn=rn%50;
j=rn/20;
n20=(int) j;
rn=rn%20;
j=rn/10;
n10=(int) j;
rn=rn%10;
j=rn/5;
n5=(int) j;
rn=rn%5;
j=rn/2;
n2=(int) j;
rn=rn%2;
j=rn/1;
p1=(int) j;
rn=rn%1;
j=rn/0.5;
p50=(int) j;
rn=rn%0.5;
j=rn/0.25;
p25=(int) j;
rn=rn%0.25;
j=rn/0.10;
p10=(int) j;
rn=rn%0.10;
j=rn/0.05;
p5=(int) j;
rn=rn%0.05;
j=rn/0.01;
p01=(int) j;
}
System.out.println("NOTAS:");
System.out.println(n100+" nota(s) de R$ 100.00");
System.out.println(n50+" nota(s) de R$ 50.00");
System.out.println(n20+" nota(s) de R$ 20.00");
System.out.println(n10+" nota(s) de R$ 10.00");
System.out.println(n5+" nota(s) de R$ 5.00");
System.out.println(n2+" nota(s) de R$ 2.00");
System.out.println("MOEDAS:");
System.out.println(p1+" moeda(s) de R$ 1.00");
System.out.println(p50+" moeda(s) de R$ 0.50");
System.out.println(p25+" moeda(s) de R$ 0.25");
System.out.println(p10+" moeda(s) de R$ 0.10");
System.out.println(p5+" moeda(s) de R$ 0.05");
System.out.println(p01+" moeda(s) de R$ 0.01");
}
}
Why is this not accepting in JAVA? Showing 10% error. Please, help me with this code.
ReplyDeleteimport java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner ler = new Scanner(System.in);
double x;
double moeda1=0, moeda2=0, moeda3=0, moeda4=0, moeda5=0, moeda6=0, nota=0, nota1=0, nota2=0, nota3=0, nota4=0, nota5=0, nota6=0;;
x = ler.nextDouble();
if (x >= 100) {
nota = x / 100;
nota = (int) x;
x = x - (nota * 100);
}
if (x >= 50) {
nota1 = x / 50;
nota1 = (int) x;
x = x - (nota1 * 50);
}
if (x >= 20) {
nota2 = x / 20;
x = x - (nota2 * 20);
}
if (x >= 10) {
nota3 = x / 10;
x = x - (nota3 * 10);
}
if (x >= 5) {
nota4 = x / 5;
x = x - (nota4 * 5);
}
if (x >= 2) {
nota5 = x / 2;
x = x - (nota5 * 2);
}
if (x >= 1) {
moeda1 = x / 1;
x = x - (moeda1 * 1);
}
if (x >= 0.50) {
moeda2 = x / 0.50;
x = x - (moeda2 * 0.50);
}
if (x >= 0.25) {
moeda3 = x / 0.25;
x = x - (moeda3 * 0.25);
}
if (x >= 0.10) {
moeda4 = x / 0.10;
x = x - (moeda4 * 0.10);
}
if (x >= 0.05) {
moeda5 = x / 0.05;
x = x - (moeda5 * 0.05);
}
if (x >= 0.01) {
moeda6 = x / 0.01;
x = x - (moeda6 * 0.01);
}
System.out.println("NOTAS:");
System.out.println(nota + " nota(s) de R$ 100.00");
System.out.println(nota1 + " nota(s) de R$ 50.00");
System.out.println(nota2 + " nota(s) de R$ 20.00");
System.out.println(nota3 + " nota(s) de R$ 10.00");
System.out.println(nota4 + " nota(s) de R$ 5.00");
System.out.println(nota5 + " nota(s) de R$ 2.00");
System.out.println("MOEDAS:");
System.out.println(moeda1 + " moeda(s) de R$ 1.00");
System.out.println(moeda2 + " moeda(s) de R$ 0.50");
System.out.println(moeda3 + " moeda(s) de R$ 0.25");
System.out.println(moeda4 + " moeda(s) de R$ 0.10");
System.out.println(moeda5 + " moeda(s) de R$ 0.05");
System.out.println(moeda6 + " moeda(s) de R$ 0.01");
}
}
import java.util.Scanner;
ReplyDeletepublic class Main {
public static void main(String[] args) {
float a;
int tmp;
Scanner ssm = new Scanner(System.in);
a=ssm.nextFloat();
System.out.println("NOTAS:");
tmp=(int) (a/100);
System.out.printf("%d nota(s) de R$ 100.00\n",tmp);
tmp=(int) ((a%100)/50);
System.out.printf("%d nota(s) de R$ 50.00\n",tmp);
tmp=(int) (((a%100)%50)/20);
System.out.printf("%d nota(s) de R$ 20.00\n",tmp);
tmp=(int) ((((a%100)%50)%20)/10);
System.out.printf("%d nota(s) de R$ 10.00\n",tmp);
tmp=(int) (((((a%100)%50)%20)%10)/5);
System.out.printf("%d nota(s) de R$ 5.00\n",tmp);
tmp=(int) ((((((a%100)%50)%20)%10)%5)/2);
System.out.printf("%d nota(s) de R$ 2.00\n",tmp);
System.out.println("MOEDAS:");
tmp=(int) (((((((a%100)%50)%20)%10)%5)%2)/1);
System.out.printf("%d moeda(s) de R$ 1.00\n",tmp);
tmp=(int) ((float) (((((((a%100)%50)%20)%10)%5)%2)%1)/0.50);
System.out.printf("%d moeda(s) de R$ 0.50\n",tmp);
tmp=(int)((float) ((((((((a%100)%50)%20)%10)%5)%2)%1)%0.50)/0.25);
System.out.printf("%d moeda(s) de R$ 0.25\n",tmp);
tmp=(int) ((float) (((((((((a%100)%50)%20)%10)%5)%2)%1)%0.50)%0.25)/0.10);
System.out.printf("%d moeda(s) de R$ 0.10\n",tmp);
tmp=(int) ((float) ((((((((((a%100)%50)%20)%10)%5)%2)%1)%0.50)%0.25)%0.10)/0.05);
System.out.printf("%d moeda(s) de R$ 0.05\n",tmp);
tmp=(int) ((float) (((((((((((a%100)%50)%20)%10)%5)%2)%1)%0.50)%0.25)%0.10)%0.05)/0.01);
System.out.printf("%d moeda(s) de R$ 0.01\n",tmp);
}
}
why this program show wrong answer?