raindrops: iteration 1
This commit is contained in:
parent
21e09ea2ad
commit
67a5c26d37
1 changed files with 9 additions and 6 deletions
|
|
@ -1,14 +1,17 @@
|
||||||
#include "raindrops.h"
|
#include "raindrops.h"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace raindrops {
|
namespace raindrops {
|
||||||
|
|
||||||
using namespace std;
|
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"}};
|
{{3, "Pling"}, {5, "Plang"}, {7, "Plong"}};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -16,10 +19,10 @@ string convert(int input)
|
||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
|
|
||||||
for (auto &pair : dictionary)
|
for (auto &mapping : dictionary)
|
||||||
if (!(input % pair.first)) {
|
if (!(input % mapping.number)) {
|
||||||
|
|
||||||
result += pair.second;
|
result += mapping.word;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.empty() ? to_string(input) : result;
|
return result.empty() ? to_string(input) : result;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue