-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phone Number Combinations
62 lines (54 loc) · 1.16 KB
/
Phone Number Combinations
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
/* dpw4112001 */
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define MOD 1000000007
#define f first
#define i insert
#define all(x) x.begin(),x.end()
#define s second
#define pb push_back
#define MX 1000005
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long
string table[]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
vector<string> solve(int a[],int n)
{
queue<string>q;
vector<string>v;
q.push("");
while(!q.empty())
{
string now=q.front();
q.pop();
if(now.length()==n)
v.push_back(now);
else
{
for(auto letter:table[a[now.length()]])
q.push(now+letter);
}
}
return v;
}
int32_t main()
{IO;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
cin >>t ;
while(t--)
{
int n;
cin >> n;
int a[n];
for(int i=0;i<n;i++)
cin >> a[i];
vector<string>ans=solve(a,n);
for(auto str:ans)
cout<<str<<' ';
}
return 0;
}