What is the problem in my code?
Request to provide more typical test cases
Clarify my doubt
#include
#include
using namespace std;
char genchar(char s)
{
int i;
char c;
i=s-‘0’;
i–;
c=‘a’+i;
return c;
}
char genchar(char s1,char s2)
{
int i,j,num;
char c;
i=s1-‘0’;
j=s2-‘0’;
num=i*10+j;
num–;
c=‘a’+num;
return c;
}
void gencodes(char *inp,char *outp,int i,int j,int len)
{
if(i==len)
{
outp[j]=’\0’;
cout<<outp<<endl;
return;
}
if(inp[i]!=‘0’)
{
outp[j]=genchar(inp[i]);
gencodes(inp,outp,i+1,j+1,len);
}
if(i<len-1)
{
int k;
k=inp[i+1]-‘0’;
if(inp[i]==‘0’)
{
outp[j]=genchar(inp[i+1]);
gencodes(inp,outp,i+2,j+1,len);
}
if(inp[i]=='1')
{
outp[j]=genchar(inp[i],inp[i+1]);
//Modification:
gencodes(inp,outp,i+2,j+1,len);
}
else if(inp[i]=='2' && k<7)
{
outp[j]=genchar(inp[i],inp[i+1]);
//Modification:
gencodes(inp,outp,i+2,j+1,len);
}
// gencodes(inp,outp,i+2,j+1,len);
}
return;
}
int main()
{
char inp[1000],outp[1000];
cin>>inp;
gencodes(inp,outp,0,0,strlen(inp));
return 0;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.