-
Notifications
You must be signed in to change notification settings - Fork 62
/
KEY PAD DIALING
97 lines (63 loc) · 1.24 KB
/
KEY PAD DIALING
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<bits/stdc++.h>
using namespace std;
/*
int n,a[105];
int fun()
{
bool dp[n+1][sum+1];
for(int i=0;i<=n;i++)
{
dp[i][0]=true;
}
for(int i=1;i<=sum;i++)
{
dp[0][i]=false;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=sum;j++)
{
if(a[i-1]>j)
dp[i][j] = dp[i-1][j];
if(j>=a[i-1])
dp[i][j] = dp[i-1][j] || dp[i-1][j-a[i]];
}
}
return dp[n][sum];
}*/
map<char,string>mp;
void print_str(string number,int i,string ans)
{
if(i==number.length())
{
cout<<ans<<" ";
return;
}
string s=mp[number[i]];
for(auto x:s)
{
ans+=x;
print_str(number,i+1,ans);
ans.erase(ans.length()-1,1);
}
}
void key_pad_dialing(string number)
{
mp['0']="0";
mp['1']="1";
mp['2']="ABC";
mp['3']="DEF";
mp['4']="GHI";
mp['5']="JKL";
mp['6']="MNO";
mp['7']="PQRS";
mp['8']="TUV";
mp['9']="WXYZ";
string ans="";
print_str(number,0,ans);
}
int main()
{
string s; cin>>s;
key_pad_dialing(s);
}