-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1315 from thecreatorsir/my_branch
coin chage problem
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |