1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
std::vector<std::string> separate(const std::string& input)
{
std::vector<std::string> parts;
auto prev = input.begin();
do {
//http://en.cppreference.com/w/cpp/algorithm/adjacent_find
auto it = std::adjacent_find(prev, input.end(), std::not_equal_to<>());
if(it != input.end()) ++it;
parts.emplace_back(prev, it);
prev = it;
} while (prev != input.end());
return parts;
}
std::string decypher(const std::string& input)
{
static const std::map<std::string, char> chars {
{"2", 'A'}, {"22", 'B'}, {"222", 'C'}, {"3", 'D'}, {"33", 'E'}, {"333", 'F'}, {"0", ' '},
{"4", 'G'}, {"44", 'H'}, {"444", 'I'}, {"5", 'J'}, {"55", 'K'}, {"555", 'L'},
{"6", 'M'}, {"66", 'N'}, {"666", 'O'}, {"7", 'P'}, {"77", 'Q'}, {"777", 'R'}, {"7777", 'S'},
{"8", 'T'}, {"88", 'U'}, {"888", 'V'}, {"9", 'W'}, {"99", 'X'}, {"999", 'Y'}, {"9999", 'Z'},
};
std::string result;
for(const auto& str: separate(input))
if(chars.find(str) != chars.end())
result += chars.at(str);
return result;
}
int main()
{
std::cout << decypher("44335551555666096667775553") << '\n';
}
|
HELLO WORLD |