diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-13 19:10:05 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-13 20:30:16 +0100 |
commit | 2cf6b010e0a2fb678846d7a2e9ab64d23c49bb7b (patch) | |
tree | 79e6a3900fb3a288962cabd572ed942fc77b74c5 /01-algorithmic_toolbox/02-greedy_algorithms/01-change/change.cpp | |
parent | e72410168143db1b79ee30e47d68cca2d730f740 (diff) | |
download | coursera-2cf6b010e0a2fb678846d7a2e9ab64d23c49bb7b.zip coursera-2cf6b010e0a2fb678846d7a2e9ab64d23c49bb7b.tar.gz |
Algorithms : complete 01-algorithmic_toolbox 02-greedy_algorithms
Diffstat (limited to '01-algorithmic_toolbox/02-greedy_algorithms/01-change/change.cpp')
-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() { |