From 2cf6b010e0a2fb678846d7a2e9ab64d23c49bb7b Mon Sep 17 00:00:00 2001 From: Jérémy Zurcher Date: Sun, 13 Nov 2016 19:10:05 +0100 Subject: Algorithms : complete 01-algorithmic_toolbox 02-greedy_algorithms --- .../02-greedy_algorithms/01-change/change.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to '01-algorithmic_toolbox/02-greedy_algorithms/01-change') diff --git a/01-algorithmic_toolbox/02-greedy_algorithms/01-change/change.cpp b/01-algorithmic_toolbox/02-greedy_algorithms/01-change/change.cpp index e25cd67..612066b 100644 --- a/01-algorithmic_toolbox/02-greedy_algorithms/01-change/change.cpp +++ b/01-algorithmic_toolbox/02-greedy_algorithms/01-change/change.cpp @@ -1,8 +1,23 @@ #include -int get_change(int n) { - //write your code here - return n; +int get_change(int n) +{ + int N = 0; + + while(n >= 10) { + n -= 10; + N += 1; + } + while(n >= 5) { + n -= 5; + N += 1; + } + while(n >= 1) { + n -= 1; + N += 1; + } + + return N; } int main() { -- cgit v1.2.3