Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Note{
- int value;
- int count;
- };
- void greedyKnapsackMoney(Note note[], int n, int amount)
- {
- int i,currentAmount=0;
- for(i=0;i<n;i++)
- {
- if(currentAmount+note[i].value<= amount)
- {
- currentAmount = currentAmount+note[i].value;
- note[i].count++;
- i--;
- }
- }
- cout << "\n\n----------------------"<<endl;
- for(i=0; i<n; i++)
- {
- if(note[i].count != 0)
- {
- cout << " " << note[i].value << " Taka Quantity--> " << note[i].count <<endl;
- }
- }
- }
- int main()
- {
- int amount;
- cout << "Input Amount: ";
- cin >> amount;
- int noteValue[9] = {1000,500,100,50,20,10,5,2,1};
- Note note[9];
- for(int i=0; i<9; i++)
- {
- note[i].value = noteValue[i];
- note[i].count = 0;
- }
- greedyKnapsackMoney(note,9,amount);
- return 0;
- }
Add Comment
Please, Sign In to add comment