31 lines
452 B
C++
31 lines
452 B
C++
#include "raindrops.h"
|
|
|
|
|
|
namespace raindrops {
|
|
|
|
using namespace std;
|
|
|
|
struct mapping_t
|
|
{
|
|
int number;
|
|
string word;
|
|
};
|
|
|
|
static const mapping_t dictionary[]=
|
|
{{3, "Pling"}, {5, "Plang"}, {7, "Plong"}};
|
|
|
|
|
|
string convert(int input)
|
|
{
|
|
string result;
|
|
|
|
for (auto &mapping : dictionary)
|
|
if (!(input % mapping.number)) {
|
|
|
|
result += mapping.word;
|
|
}
|
|
|
|
return result.empty() ? to_string(input) : result;
|
|
}
|
|
|
|
}
|