diff options
-rw-r--r-- | PlaygroundCpp/Sources/Playground.cpp | 79 |
1 files changed, 33 insertions, 46 deletions
diff --git a/PlaygroundCpp/Sources/Playground.cpp b/PlaygroundCpp/Sources/Playground.cpp index 2bbbeb9..fbda74a 100644 --- a/PlaygroundCpp/Sources/Playground.cpp +++ b/PlaygroundCpp/Sources/Playground.cpp @@ -1,56 +1,43 @@ #include <iostream> //#include <gtest/gtest.h> -const int FIB_PISANO_PERIOD_FOR_TEN = 60; - -static int getFibNModM(long n) { - long r = n % FIB_PISANO_PERIOD_FOR_TEN; - if (r == 0) - return 0; - int firstN = 0; - int secondN = 1; - int tempHolder = 1; - for (int i = 1; i < r; i++) { - tempHolder = (firstN + secondN) % 10; - firstN = secondN; - secondN = tempHolder; - } - return secondN; -} -static int getLastDigit(long n) { - if (n <= 1) - return (int) n; - int result = getFibNModM(n + 2); - if (result == 0) - return 9; +static int getNumOfCoins(int m) { + // coins with denominations of 1, 5, and 10 + int coinCount = 0; + int remainder; + if (m / 10 == 0 && m % 10 == 0) + return m / 10; + coinCount = coinCount + m / 10; + remainder = m % 10; + if (remainder >= 5) + return coinCount + 1 + remainder - 5; else - return result - 1; + return coinCount + remainder; } -static int getLastDigit(long m, long n) { - if (m == n) - return getFibNModM(n); - else { - int sumFn = getLastDigit(n); - int sumFm; - if (m <= 1) - sumFm = 0; - else - sumFm = getLastDigit(m - 1); - if (sumFn >= sumFm) - return sumFn - sumFm; - else - return sumFn - sumFm + 10; - } -} -//TEST(FibPartialSumLastDigit, Ten_200) { -// ASSERT_EQ(getLastDigit(10, 200), 2); -//TEST(FibPartialSumLastDigit, One_2) { -// ASSERT_EQ(getLastDigit(1, 2), 2); + +//TEST(ChangingMoney, One) { +// ASSERT_EQ(getNumOfCoins(1), 1); +//} +// +//TEST(ChangingMoney, Two) { +// ASSERT_EQ(getNumOfCoins(2), 2); +//} +// +//TEST(ChangingMoney, Six) { +// ASSERT_EQ(getNumOfCoins(6), 2); +//} +// +//TEST(ChangingMoney, TwentyEight) { +// ASSERT_EQ(getNumOfCoins(28), 6); +//} +// +//TEST(ChangingMoney, OneThousand) { +// ASSERT_EQ(getNumOfCoins(1000), 100); +//} int main() { - long m, n; + int m; std::cin >> m; - std::cin >> n; - int c = getLastDigit(m, n); + int c = getNumOfCoins(m); std::cout << c << '\n'; } |