Skip to content

Issue in cplusplus-datastructures-algorithms-coding-blocks/STL/Algori… #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Issue in cplusplus-datastructures-algorithms-coding-blocks/STL/Algori…
…thms/algo_stl_money_change_problem.cpp

Issue in cplusplus-datastructures-algorithms-coding-blocks/STL/Algorithms/algo_stl_money_change_problem.cpp . The program already present is not actual code of money change problem.That code actually depicts swap,min,max,reverse and next_pemutation. so proposing this actual code
  • Loading branch information
SIDDIQUI-SAHIL authored Mar 4, 2021
commit b9b639d678d28f37afa33690b09503978256711d
37 changes: 12 additions & 25 deletions STL/Algorithms/algo_stl_money_change_problem.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
#include <iostream>
#include<algorithm>
using namespace std;

bool compare(int a,int b){
return a<=b;
}
int main() {

int a = 10;
int b = 20;

swap(a, b);
cout << a << " and " << b << endl;

cout << max(a, b) << endl;
cout << min(a, b) << endl;

int arr[] = {1, 2, 3, 4, 4, 5};
reverse(arr, arr + 4);

swap(arr[0], arr[1]);

int n = sizeof(arr) / sizeof(int);
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
next_permutation(arr, arr + n);
cout << endl;
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
int coins[]={1,2,5,10,20,50,100,200,500,2000};
int n=sizeof(coins)/sizeof(int);
int money=168;
while(money>0){
int lb= lower_bound(coins,coins+n,money,compare)-coins-1;
int m=coins[lb];
cout<<m<<", ";
money=money-m;
}

return 0;
}