--> Banknotes and Coins (beeCrowd- 1021) URI 1021 Solution C, Python | Alpha Codist

Search This Blog

Banknotes and Coins (beeCrowd- 1021) URI 1021 Solution C, Python

banknotesandcoins1021Banknotes and Coins beeCrowd 1021 URI 1021 Solution C Python programming solved solving easy neilor tonin brazil money input 1e-9

Banknotes and Coins

banknotesandcoins1021Banknotes and Coins beeCrowd 1021 URI 1021 Solution C Python programming solved solving easy neilor tonin brazil money input 1e-9


This problem is from beeCrowd. Here, You get the amount of money as input. It is an integer. You have to calculate and print the least amount of banknotes and coins required to cover that much money. Banknotes and coins, as given, are 100,50,20,10,5,2 and 1, 0.50, 0.25, 0.10, 0.05, 0.01.

The formula is:

  1. Take input.
  2. Create a list for currency and one for currencyCount.
  3. Print "NOTAS:"
  4. Start a while loop checking for each note in currency.
  5. Run a while loop that checks if that particular note is >= inputted value.
  6. Add 1 to currencyCount lists the same index as the index of that note or coin. Subtract notes amount from money.
  7. Check if currency == 1 then, print "MOEDAS:". This way "MOEDAS:" will be printed only once.
  8. check if currency >=2 or <2. If currency >=2 print notes and if currency <2 print coins as said in beecrowd.
  9. Print


The solution in C:


#include <stdio.h>

int main() {
 
    double money;
    scanf("%lf",&money);
    double currency[12] = {100,50,20,10,5,2,1, 0.50, 0.25, 0.10, 0.05, 0.01};
    int currencyCount;
    
    printf("NOTAS:\n");
    
    money+=1e-9;
    for(int i = 0; i<=11;i++){
        currencyCount = 0;
        while(money>=currency[i]){
            currencyCount+=1;
            money-=currency[i];
        }
        if(currency[i]==1)
                printf("MOEDAS:\n");
            if(currency[i]>1){
                printf("%d nota(s) de R$ %0.2f\n",currencyCount,currency[i]);
            }
            if(currency[i]<2){
                printf("%d moeda(s) de R$ %0.2f\n",currencyCount,currency[i]);
            }
        
    }
    
 
    return 0;
}


The solution in Python:


money = float(input())
currency = [100,50,20,10,5,2,1, 0.50, 0.25, 0.10, 0.05, 0.01]

print("NOTAS:");
i = 0
money+=1e-9;
while i<=11:
    currencyCount = 0
    while money>=currency[i]:
        currencyCount+=1
        money-=currency[i]
        
    if currency[i]==1:
        print("MOEDAS:")
    if currency[i]>1:
        print("%d nota(s) de R$ %0.2f" % (currencyCount,currency[i]))
    if currency[i]<2:
        print("%d moeda(s) de R$ %0.2f" % (currencyCount,currency[i]))
    i+=1

COMMENTS

Name

beeCrowd,11,C,10,Computer,9,Downloads,3,HTML,1,My Creation,2,Python,24,Python-Soft,1,Shooting,2,
ltr
item
Alpha Codist: Banknotes and Coins (beeCrowd- 1021) URI 1021 Solution C, Python
Banknotes and Coins (beeCrowd- 1021) URI 1021 Solution C, Python
banknotesandcoins1021Banknotes and Coins beeCrowd 1021 URI 1021 Solution C Python programming solved solving easy neilor tonin brazil money input 1e-9
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9deBy5fnCMO7nolF5UALqHU0Jc84iywOnb7UfOjvnxkefAi-v1U6YimAsXNFf8F0cJoOfAWH84MCwnqQRPO2pkXgXuPwH6OcWKWd-WNHmfQMnYs8K-5jMKihbk3pLoO9D31h8fuaw9tp-0h26GuUsTzZe3Z8LAfU9gWupGJ2GerYL3HWryJ2rqfbOOg/w640-h422/1021.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9deBy5fnCMO7nolF5UALqHU0Jc84iywOnb7UfOjvnxkefAi-v1U6YimAsXNFf8F0cJoOfAWH84MCwnqQRPO2pkXgXuPwH6OcWKWd-WNHmfQMnYs8K-5jMKihbk3pLoO9D31h8fuaw9tp-0h26GuUsTzZe3Z8LAfU9gWupGJ2GerYL3HWryJ2rqfbOOg/s72-w640-c-h422/1021.png
Alpha Codist
https://alphacodist.blogspot.com/2022/12/banknotesandcoins1021.html
https://alphacodist.blogspot.com/
https://alphacodist.blogspot.com/
https://alphacodist.blogspot.com/2022/12/banknotesandcoins1021.html
true
7547834254111195316
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content