Banknotes beeCrowd- 1018 URI 1018 Solution C Python solved very easily neilor tonin uri int programming problem solving coding alpha codist easy py c
Banknotes
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 required to cover that much money. Banknotes, as given, are 100,50,20,10,5,2,1.
The formula is:
- Take input.
- Create a list for banknotes and one for banknoteCount.
- Print the value of money.
- Start a for loop while checking for each note in banknotes.
- Run a while loop that checks if that particular note is >= inputted value.
- Add 1 to banknoteCount lists same index as the index of that note. Subtract notes amount from money.
The solution in C:
#include <stdio.h>
int main() {
int money;
scanf("%d",&money);
int banknotes[7] = {100,50,20,10,5,2,1};
int banknoteCount[7] = {};
printf("%d\n",money);
for(int i = 0; i<=6;i++){
while(money>=banknotes[i]){
banknoteCount[i]+=1;
money-=banknotes[i];
}
printf("%d nota(s) de R$ %d,00\n",banknoteCount[i],banknotes[i]);
}
return 0;
}
The solution in Python:
money = int(input())
banknotes = [100,50,20,10,5,2,1]
banknoteCount = [0,0,0,0,0,0,0]
print("%d" % money)
for note in banknotes:
while note <= money:
banknoteCount[banknotes.index(note)]+=1
money -= note
print("%d nota(s) de R$ %d,00" % (banknoteCount[banknotes.index(note)],note))
COMMENTS