forked from Priyadarshan2000/Hacktoberfest_2k22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
possible_words_frm_phn_digits.cpp
65 lines (48 loc) · 1.23 KB
/
possible_words_frm_phn_digits.cpp
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
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
#include<string>
using namespace std;
class Solution
{
public:
vector<string> possibleWords(int a[], int N)
{
unordered_map<int, vector<string>>M;
M[2] = {"a", "b", "c"};
M[3] = {"d", "e", "f"};
M[4] = {"g", "h", "i"};
M[5] = {"j", "k", "l"};
M[6] = {"m", "n", "o"};
M[7] = {"p", "q", "r", "s"};
M[8] = {"t", "u", "v"};
M[9] = {"w", "x", "y", "z"};
vector<string> first = M[a[0]];
for(int i=1; i<N; i++)
{
vector<string> second = M[a[i]], ans;
for(auto f:first)
{
for(auto s:second)
ans.push_back(f+s);
}
first = ans;
}
return first;
}
};
int main() {
int T;
cin >> T;
while(T--){
int N;
cin >> N;
int a[N];
for(int i =0;i<N;i++){
cin >> a[i];
}
Solution obj;
vector <string> res = obj.possibleWords(a,N);
for (string i : res) cout << i << " ";
cout << endl;
}
return 0;
}