Skip to content

Commit

Permalink
Merge pull request #232 from Coder-2022/main
Browse files Browse the repository at this point in the history
Create Print_Keypad_Combinations_Code.cpp
  • Loading branch information
AkshayNachappa authored Oct 26, 2021
2 parents 392996a + 8bbcdfb commit 69c6131
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions CPP/Print_Keypad_Combinations_Code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* 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 printer(string* temp, int n, string output)
{
if (n==0)
{
cout << output << endl;
return;
}
int last_digit = n % 10;
string s = temp[last_digit];

for(int i=0; i<s.size(); i++)
{
printer(temp, n / 10, s[i]+output);
}
if(s.size()==0)
{
printer(temp, n / 10, output);
}
}
void printKeypad(int n)
{
string* temp = new string[10];
temp[0] = "";
temp[1] = "";
temp[2] = "abc";
temp[3] = "def";
temp[4] = "ghi";
temp[5] = "jkl";
temp[6] = "mno";
temp[7] = "pqrs";
temp[8] = "tuv";
temp[9] = "wxyz";
printer(temp, n, "");
}

int main(){
int num;
cin >> num;

printKeypad(num);

return 0;
}

0 comments on commit 69c6131

Please sign in to comment.