From ade6d14753554bdbec0dab3639dec3158c17a38a Mon Sep 17 00:00:00 2001 From: Harshil Kaneria <71480025+Harshil26202@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:08:59 +0530 Subject: [PATCH] Add files via upload algorithm toolbox week 3 greedy algorithm solution 1 --- coursera w3.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 coursera w3.cpp diff --git a/coursera w3.cpp b/coursera w3.cpp new file mode 100644 index 0000000..e58c123 --- /dev/null +++ b/coursera w3.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +int get_change(int m) { + int j=0,n=0; + if(m>=10) + { + j=m/10; + m=m%10; + n=n+j; + } + if(m>=5&&m<10) + { + j=m/5; + m=m%5; + n=n+j; + } + if(m>=1&&m<5) + { + j=m; + m=0; + n=n+j; + } + return n; +} + +int main() { + int m; + std::cin >> m; + std::cout << get_change(m) << '\n'; + return 0; +} +