raindrops: iteration 1

This commit is contained in:
Dmitry Kokorin 2016-03-20 19:25:03 +03:00
parent 21e09ea2ad
commit 67a5c26d37

View file

@ -1,14 +1,17 @@
#include "raindrops.h"
#include <map>
namespace raindrops {
using namespace std;
typedef map<int, string> dictionary_t;
struct mapping_t
{
int number;
string word;
};
static const dictionary_t dictionary =
static const mapping_t dictionary[]=
{{3, "Pling"}, {5, "Plang"}, {7, "Plong"}};
@ -16,10 +19,10 @@ string convert(int input)
{
string result;
for (auto &pair : dictionary)
if (!(input % pair.first)) {
for (auto &mapping : dictionary)
if (!(input % mapping.number)) {
result += pair.second;
result += mapping.word;
}
return result.empty() ? to_string(input) : result;