raindrops: tests are passed

This commit is contained in:
Dmitry Kokorin 2016-03-20 19:07:20 +03:00
parent 5120da5fa9
commit 21e09ea2ad
2 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,28 @@
#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;
}
}

11
cpp/raindrops/raindrops.h Normal file
View file

@ -0,0 +1,11 @@
#pragma once
#define EXERCISM_RUN_ALL_TESTS
#include <string>
namespace raindrops {
std::string convert(int);
}