diff options
Diffstat (limited to '01-algorithmic_toolbox/02-greedy_algorithms/01-change')
-rw-r--r-- | 01-algorithmic_toolbox/02-greedy_algorithms/01-change/change.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
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 <iostream> -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() { |