Return Keypad Code
Return Keypad Code
Send Feedback
Return Keypad Code
Integer n
All possible strings in different lines
23
ad
ae
af
bd
be
bf
cd
ce
cf
#include <string>using namespace std;
int keypad(int num, string output[]){ string str[] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; if(num==0){ output[0]=""; return 1; } int lnum=num%10; int rnum=num/10; string smalloutput[10000]; int t = keypad(rnum,smalloutput); int k=0; string s = str[lnum]; int l =s.length(); for(int i=0; i<t; i++){ for(int j=0; j<l; j++){ output[k]=smalloutput[i]+s[j]; k++; } } return k; }
#include <iostream>#include <string>using namespace std;
#include <string>using namespace std;
int keypad(int num, string output[]){ string str[] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; if(num==0){ output[0]=""; return 1; } int lnum=num%10; int rnum=num/10; string smalloutput[10000]; int t = keypad(rnum,smalloutput); int k=0; string s = str[lnum]; int l =s.length(); for(int i=0; i<t; i++){ for(int j=0; j<l; j++){ output[k]=smalloutput[i]+s[j]; k++; } } return k; }
int main(){ int num; cin >> num;
string output[10000]; int count = keypad(num, output); for(int i = 0; i < count && i < 10000; i++){ cout << output[i] << endl; } return 0;}
Comments
Post a Comment