TITLE:-
Return Keypad Code
PROBLEM:-
Integer n
All possible strings in different lines
23
ad
ae
af
bd
be
bf
cd
ce
cf
SOLUTION:-
#include <iostream> #include <string> using namespace std;
#include <string>
using namespace std;
int keypad(int num, string output[]){
/* Insert all the possible combinations of the integer number into the output string array. You do not need to
print anything, just return the number of strings inserted into the array.
*/
if(num <0)
return -1;
if(num==0||num==1)
{
output[0]="";
return 1;
}
int smallnum=num/10;
int renum=num%10;
int smallcount=keypad(smallnum,output);
int vo;
string s[]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
if(renum==7||renum==9)
vo=4;
else
vo=3;
int j=0;
int c=0;
string output1[10000];
while(j<vo)
{
for(int i=0;i<smallcount;i++)
{
output1[c]=output[i] +s[renum-2][j];
c++;
}
j++;
}
for(int i=0;i<c;i++)
{
output[i]=output1[i];
}
return vo*smallcount;
}
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; }
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon