exercism-solutions/cpp/raindrops/raindrops.cpp

28 lines
440 B
C++

#include "raindrops.h"
#include <map>
namespace raindrops {
using namespace std;
typedef map<int, string> 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;
}
}