diff --git a/cpp/raindrops/raindrops.cpp b/cpp/raindrops/raindrops.cpp new file mode 100644 index 0000000..5314f9d --- /dev/null +++ b/cpp/raindrops/raindrops.cpp @@ -0,0 +1,28 @@ +#include "raindrops.h" + +#include + +namespace raindrops { + +using namespace std; + +typedef map dictionary_t; + +static const dictionary_t dictionary = + {{3, "Pling"}, {5, "Plang"}, {7, "Plong"}}; + + +string convert(int input) +{ + string result; + + for (auto &pair : dictionary) + if (!(input % pair.first)) { + + result += pair.second; + } + + return result.empty() ? to_string(input) : result; +} + +} diff --git a/cpp/raindrops/raindrops.h b/cpp/raindrops/raindrops.h new file mode 100644 index 0000000..636f07f --- /dev/null +++ b/cpp/raindrops/raindrops.h @@ -0,0 +1,11 @@ +#pragma once + +#define EXERCISM_RUN_ALL_TESTS + +#include + +namespace raindrops { + +std::string convert(int); + +}