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 N (0 ≤ N ≤ 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 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n;
scanf("%lf",&n);
printf("NOTAS:\n");
int a=n;
int c=a;
printf("%d nota(s) de R$ 100.00\n",a/100);
a=a%100;
printf("%d nota(s) de R$ 50.00\n",a/50);
a=a%50;
printf("%d nota(s) de R$ 20.00\n",a/20);
a=a%20;
printf("%d nota(s) de R$ 10.00\n",a/10);
a=a%10;
printf("%d nota(s) de R$ 5.00\n",a/5);
a=a%5;
printf("%d nota(s) de R$ 2.00\n",a/2);
a=a%2;
printf("MOEDAS:\n");
int b=(n-c)*100;
printf("%d moeda(s) de R$ 1.00\n",a);
printf("%d moeda(s) de R$ 0.50\n",b/50);
b=b%50;
printf("%d moeda(s) de R$ 0.25\n",b/25);
b=b%25;
printf("%d moeda(s) de R$ 0.10\n",b/10);
b=b%10;
printf("%d moeda(s) de R$ 0.05\n",b/5);
b=b%5;
printf("%d moeda(s) de R$ 0.01\n",b/1);
}
Comments
Post a Comment