forked from shruti-singh-3/Hacktober_open_source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keypad Combinations Code
51 lines (41 loc) · 923 Bytes
/
Keypad Combinations Code
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
/* Given an integer n, using phone keypad find out and print all the possible strings that can be made using digits of input n.
Sample Input:
23
Sample Output:
ad
ae
af
bd
be
bf
cd
ce
cf */
#include <iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
//Keypad
string key[]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
//0 , 1, 2 ,3 ,4 , 5 ,6 ,7 ,8 ,9
void keypad(int num,string output)
{
if(num==0)
{
cout<<output<<endl;
return ;
}
string temp=key[num%10]; // taking string corresponding to last digit
for(int i=0;i<temp.size();i++)
keypad(num/10,temp[i]+output); // taking every ch of temp in output
}
void printKeypad(int num)
{
string output="";
keypad(num,output);
}
int main(){
int num;
cin >> num;
printKeypad(num);
return 0;