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 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
using Keypad = std::map<char, std::vector<char>>;
const Keypad keys{{'2', {'a','b','c'}}, {'3', {'d','e','f'}}, {'4', {'g','h','i'}}, {'5',{'j','k','l'}},
{'6', {'m','n','o'}}, {'7', {'p','q','r','s'}}, {'8',{'t','u','v'}}, {'9',{'w','x','y','z'}}};
int main()
{
std::cout << "Enter telephone number: \n";
std::string telNumber{};
getline(std::cin, telNumber);
if((telNumber.size() != 7) || !(std::all_of(telNumber.begin(), telNumber.end(), ::isdigit)))
{
std::cout << "invalid number \n";
}
std::vector<std::vector<char>> telNumberKeys{};
for (const auto& elem : telNumber)
{
telNumberKeys.push_back(keys.find(elem)->second);
}
for (const auto& elem0 : telNumberKeys[0])
{
for (const auto& elem1 : telNumberKeys[1])
{
for (const auto& elem2 : telNumberKeys[2])
{
for (const auto& elem3 : telNumberKeys[3])
{
for (const auto& elem4 : telNumberKeys[4])
{
for (const auto& elem5 : telNumberKeys [5])
{
for (const auto& elem6 : telNumberKeys [6])
{
std::string myString = std::string(1, elem0) + std::string(1, elem1) + std::string(1, elem2)
+ std::string(1, elem3) + std::string(1, elem4) + std::string(1, elem5) + std::string(1, elem6);
std::cout << myString << "\n";
}
}
}
}
}
}
}
}
|