-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmobileKeypad.cpp
More file actions
58 lines (54 loc) · 1.13 KB
/
mobileKeypad.cpp
File metadata and controls
58 lines (54 loc) · 1.13 KB
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
//Print all possible words from phone digits
// / 1 / / 2 / / 3 /
// / / /abc/ /def/
// / 4 / / 5 / / 6 /
// /ghi/ /jkl/ /mno/
// / 7 / / 8 / / 9 /
// /pqrs/ /tuv/ /wxyz/
// / * / / 0 / / # /
// / / / / / /
#include<iostream>
#include<cstdio>
using namespace std;
int tmp[1000],total_strings=0;
int str[10][5]={
{0},
{0},
{3,'a','b','c'},
{3,'d','e','f'},
{3,'g','h','i'},
{3,'j','k','l'},
{3,'m','n','o'},
{4,'p','q','r','s'},
{3,'t','u','v'},
{4,'w','x','y','z'}
};
void recurAndPrint(string number,int n,int i){
if(number[i]=='0'||number[i]=='1')
{ //0 and 1 will not generate any char
recurAndPrint(number,n,i+1);
return ;
}
if(i==n)
{ //base case
total_strings++;
for(int x=0;x<n;x++)
cout<<(char)tmp[x];
cout<<endl;
}
int k=str[number[i]-'0'][0];
for(int j=1;j<=k;j++){
tmp[i]=str[number[i]-'0'][j];
recurAndPrint(number,n,i+1);
}
}
int main()
{
string number;
cin>>number;
int len=number.length();
recurAndPrint(number,len,0);
cout<<endl;
cout<<"Total no of strings = "<<total_strings<<endl;
return 0;
}