Skip to main content

URI Online Judge Solution 1021 Banknotes and Coins


URI Online Judge Solution 1021 Banknotes and Coins using Python Programming Language.

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

Solution

from math import * 
A = float(input()) 
T = floor(A) 
P = A - T 
T100 = T50= T20 = T10 = T5 = T2 = T1 = P50 = P25 = P10 = P5 = P1 = 0 
if A>=100: 
    T100 = int(A/100) 
    A = A%100 
if A>=50: 
   T50 = int(A/50) 
   A = A%50 
if A>=20: 
   T20 = int(A/20) 
   A = A%20 
if A>=10: 
   T10 = int(A/10) 
   A = A%10 
if A>=5: 
   T5 = int(A/5) 
   A = A%5 
if A>=2: 
   T2 = int(A/2) 
   A = A%2 
if A>=1: 
   T1 = int(A/1) 
   A = A%1 
if A>=0.5: 
   P50 = int(A/0.5) 
   A = A%0.5 
if A>=0.25: 
   P25 = int(A/0.25) 
   A = A%0.25 
if A>=0.10: 
   P10 = int(A/0.10) 
   A = A%0.10 
if A>=0.05: 
   P5 = int(A/0.05) 
   A = A%0.05 
else: 
  P1 = int(A/0.01) 
print("NOTAS:") 
print("%d nota(s) de R$ 100.00" % T100) 
print("%d nota(s) de R$ 50.00" % T50) 
print("%d nota(s) de R$ 20.00" % T20) 
print("%d nota(s) de R$ 10.00" % T10) 
print("%d nota(s) de R$ 5.00" % T5) 
print("%d nota(s) de R$ 2.00" % T2) 
print("MOEDAS:") 
print("%d moeda(s) de R$ 1.00" % T1) 
print("%d moeda(s) de R$ 0.50" % P50) 
print("%d moeda(s) de R$ 0.25" % P25) 
print("%d moeda(s) de R$ 0.10" % P10) 
print("%d moeda(s) de R$ 0.05" % P5) 
print("%d moeda(s) de R$ 0.01" % P1)

  Using C Programming Language

#include  
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; 
}

Comments

Popular posts from this blog

URI Problem 1001 Solution Extremely Basic - - URI Online Judge Solution

URI Online Judge Problem 1001 Extremely Basic Solution using C, Python Programming Language. Read 2 variables, named  A  and  B  and make the sum of these two variables, assigning its result to the variable  X . Print  X  as shown below. Print endline after the result otherwise you will get “ Presentation Error ”. Input The input file will contain 2 integer numbers. Output Print the letter  X  (uppercase) with a blank space before and after the equal signal followed by the value of X, according to the following example. Obs.: don't forget the endline after all. Samples Input Samples Output 10 9 X = 19 -10 4 X = -6 15 -7 X = 8 URI 1001 Solution in Python A = int(input()) B = int(input()) X = A + B print("X =",X); URI 1001 Solution in C: #include int main() { int A,B,X; scanf ("%d %d", &A, &B); X=A+B; printf("X = %d\n",X); return 0; }

URI Online Judge Solution 1069 Diamonds and Sand

URI Online Judge Solution 1069  Diamonds and Sand using Python Programming Language. John is working in a diamond mine, trying to extract the highest number of diamond "<>". He must exclude all sand particles found "." in this process and after a diamond can be extracted, new diamonds can be formed. If he has as an input. <... << .. >> ....> .... >>>. three diamonds are formed. The first is taken from <..> resulting. <... <> ....> .... >>>. The second diamond is then removed, leaving. <.......> .... >>>. The third diamond is then removed, leaving at the end ..... >>>. without the possibility of extracting new diamonds. Input Read an integer N that is the number of test cases. Then follows N lines each up to 1000 characters, including "<" ,">" and "." Output You must print the amount of diamonds that can be extrated in each test ca...

URI Problem 1002 Solution Area of a Circle - URI Online Judge Solution

URI Online Judge Problem 1002 Solution Area of a Circle using Python Programming Language. The formula to calculate the area of a circumference is defined as A = π . R2. Considering to this problem that π = 3.14159: Calculate the area using the formula given in the problem description. Input  The input contains a value of floating point (double precision), that is the variable R. Output  Present the message "A=" followed by the value of the variable, as in the example bellow, with four places after the decimal point. Use all double precision variables. Like all the problems, don't forget to print the end of line after the result, otherwise you will receive "Presentation Error". Input Samples Output Samples 2.00 A=12.5664 100.64 A=31819.3103 150.00 A=70685.7750 URI 1002 Solution in Python R = float(input()); R = R*R*3.14159; print("A=%.4f" % R); URI 1002 Solution in C: #include #define A 3.14159 int main() {...