aboutsummaryrefslogtreecommitdiff
path: root/challenge-160/deadmarshal/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-160/deadmarshal/cpp/ch-1.cpp')
-rw-r--r--challenge-160/deadmarshal/cpp/ch-1.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-160/deadmarshal/cpp/ch-1.cpp b/challenge-160/deadmarshal/cpp/ch-1.cpp
new file mode 100644
index 0000000000..4db8e75aa7
--- /dev/null
+++ b/challenge-160/deadmarshal/cpp/ch-1.cpp
@@ -0,0 +1,32 @@
+#include<iostream>
+#include<string>
+#include<map>
+
+std::string four_is_magic(int n)
+{
+ std::map<int, std::string> numbers{};
+ std::string ret{};
+ std::string arr[] = {"one","two","three","four","five","six","seven",
+ "eight","nine"};
+ for(int i = 0; i < 9; ++i){
+ numbers[i+1] = arr[i];
+ }
+ size_t len = numbers[n].size();
+ do{
+ ret += numbers[n] + " is " + numbers[len] + ", ";
+ n = len;
+ len = numbers[n].size();
+ }while(n != 4);
+ ret[0] = std::toupper(ret[0]);
+ ret += "four is magic.";
+ return ret;
+}
+
+int main()
+{
+ std::cout << four_is_magic(5) << '\n';
+ std::cout << four_is_magic(7) << '\n';
+ std::cout << four_is_magic(6) << '\n';
+
+ return 0;
+}