summaryrefslogtreecommitdiff
path: root/PlaygroundCpp
diff options
context:
space:
mode:
authorHaidong Ji2018-09-02 21:05:55 -0500
committerHaidong Ji2018-09-02 21:05:55 -0500
commitc6ad5d0aef9529a62e0786c97e8447c7d0f0db6a (patch)
tree3c6083fd9626ed87e2f4705862d86b8683a50c0d /PlaygroundCpp
parent38e8b768a30721a575abe6613f6492d3bb06d806 (diff)
Changing money done.
I noticed that in this case, it was really simple, because I pretty much copied the code from Java.
Diffstat (limited to 'PlaygroundCpp')
-rw-r--r--PlaygroundCpp/Sources/Playground.cpp79
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';
}