Mapped Strings question in Recursion Challenges

#include
#include
#include
#include
#include

using namespace std;

map<int,char> m = {{1,β€˜A’}, {2,β€˜B’}, {3,β€˜C’}, {4,β€˜D’}, {5,β€˜E’}, {6,β€˜F’}, {7,β€˜G’}, {8,β€˜H’}, {9,β€˜I’}, {10,β€˜J’}, {11,β€˜K’}, {12,β€˜L’}, {13,β€˜M’}, {14,β€˜N’}, {15,β€˜O’}, {16,β€˜P’}, {17,β€˜Q’}, {18,β€˜R’}, {19,β€˜S’}, {20,β€˜T’}, {21,β€˜U’}, {22,β€˜V’}, {23,β€˜W’}, {24,β€˜X’}, {25,β€˜Y’}, {26,β€˜Z’}};

void fnct(vector n, int i, int s, string ans)
{
if(i==s)
{
ans.push_back(’\0’);
cout<<ans<<endl;
return;
}

ans.push_back(m[n[i]]);
fnct(n,i+1,s,ans);
ans.pop_back();

if(i<s-1)
{
	int a=n[i];
    int b=n[i+1];

    b=10*a + b;
    if(b<=26)
    {
	   ans.push_back(m[b]);
	   fnct(n,i+2,s,ans);
    }
}

return;

}

int main() {

string ans;
vector<int> n;
int num,s=0;
cin>>num;

while(num!=0)
{
	n.push_back(num%10);
	num=num/10;
	s++;
}

reverse(n.begin(),n.end());


fnct(n,0,s,ans);
return 0;

}

GETTING WRONG ANSWER ON SUBMISSION

refer my code https://ide.codingblocks.com/s/609868
and whenever u share ur code kindly save it on ide and then send link…

Thank you for the solution Vaibhav.
I reckon this is the same solution that was shown in the video lecture.
Could you as well tell me what was wrong in the code that I had written ??
Here is the link to the IDE

okay… let me see…

okay so i dont know exactly what soln has been taught in video lecture… but by comparing both ur and my code i can see that ur code fails on test cases having 0 in them… for that u would have to map 0 with @ symbol…

1 Like

Oh okay okay
Thank you so much man !!

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.

1 Like