-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordsReplacingNosWithAlphabets.cpp
More file actions
54 lines (45 loc) · 997 Bytes
/
Copy pathWordsReplacingNosWithAlphabets.cpp
File metadata and controls
54 lines (45 loc) · 997 Bytes
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
54
#include <iostream>
#include <vector>
#include <string>
// Link: Techie deligh: https://www.techiedelight.com/combinations-of-words-formed-replacing-given-numbers-corresponding-english-alphabet/
// 1 ---> 65
// 2 ---> 66
// 3 ---> 67
class AphabetConverter
{
private:
const std::string alphabets;
public:
AphabetConverter()
: alphabets("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
{
}
void convert(const std::vector<int>& arr)
{
std::string converted;
convertHelper(arr, 0, converted);
}
private:
void convertHelper(const std::vector<int>& arr, int curr_index, std::string convertered)
{
if (curr_index == arr.size())
{
std::cout << convertered << std::endl;
return;
}
int sum = 0;
for (int i = curr_index; i < arr.size(); ++i)
{
sum = (sum * 10) + arr[i];
if (sum <= 26)
convertHelper(arr, i + 1, convertered + alphabets[sum - 1]);
}
}
};
int main()
{
std::vector<int> arr{ 1, 2, 2 };
AphabetConverter obj;
obj.convert(arr);
return 0;
}