raindrops: tests are passed
This commit is contained in:
parent
5120da5fa9
commit
21e09ea2ad
2 changed files with 39 additions and 0 deletions
28
cpp/raindrops/raindrops.cpp
Normal file
28
cpp/raindrops/raindrops.cpp
Normal 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
11
cpp/raindrops/raindrops.h
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define EXERCISM_RUN_ALL_TESTS
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace raindrops {
|
||||||
|
|
||||||
|
std::string convert(int);
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue