-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathprint_keypad_combinations_code.cpp
More file actions
50 lines (42 loc) · 942 Bytes
/
print_keypad_combinations_code.cpp
File metadata and controls
50 lines (42 loc) · 942 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
/*
Given an integer n, using phone keypad find out and print all the possible strings that can be made using digits of input n.
Note : The order of strings are not important. Just print different strings in new lines.
Input Format :
Integer n
Output Format :
All possible strings in different lines
Constraints :
1 <= n <= 10^6
Sample Input:
23
Sample Output:
ad
ae
af
bd
be
bf
cd
ce
cf
*/
#include <iostream>
#include <string>
using namespace std;
void print(int num, string output)
{ string s[8] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
if(num == 0)
{ cout<<output<<"\n";
return;
}
for(int k = 0;k<s[(num%10)-2].length();k++)
{
print(num/10 ,s[(num%10)-2][k]+output);
}
}
void printKeypad(int num){
/*
Given an integer number print all the possible combinations of the keypad. You do not need to return anything just print them.
*/
print(num,"");
}