Skip to content

Commit

Permalink
Merge pull request #1315 from thecreatorsir/my_branch
Browse files Browse the repository at this point in the history
coin chage problem
  • Loading branch information
fineanmol authored Nov 2, 2021
2 parents 3edfec8 + a884ef2 commit a5cafcb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions coin_change.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <bits/stdc++.h>
using namespace std;

int money_change(int *coin,int n,int money){
int ans = 0;
while(money>0){
int idx = upper_bound(coin,coin+n,money)-coin-1;
money = money - coin[idx];
ans++;
}
return ans;
}

int main() {
int money;
cin>>money;
int coin[]={1,2,5,10,20,50,100,200,500,2000};
int size = sizeof(coin)/sizeof(int);
cout<<money_change(coin,size,money);
}

0 comments on commit a5cafcb

Please sign in to comment.