Code gives wrong answer at all testcases

#include <bits/stdc++.h>

using namespace std;

void codeToString(string s, string ans)
{

if(s.length() == 0)
{
    cout<<ans<<" ";
    return;
}

else if(s.length() == 1)
{
    char ch1 = s.at(0);
    if(ch1=='0')
    {
        return;
    }
    else
    {
        int chv1 = ch1 - '0';
        char code = (char)('a' + chv1 - 1);
        ans += code;
        cout<<ans<<" ";
    }
}

else
{
    char ch2 = s.at(0);
    string s1 = s.substr(1);
    
    if(ch2 =='0')
    {
        return;
    }
    else
    {
        int chv2 = ch2 - '0';
        char code = (char)('a' + chv2 - 1);
        codeToString(s1,ans+code);
    }
    
    string ch12 = s.substr(0,2);
    string s12 = s.substr(2);
    
    int chv12 = stoi(ch12);
    
    if(chv12<=26)
    {
        char code = (char)('a' + chv12 - 1 );
        codeToString(s12, ans+code);
    }
}

}

int main()
{
string s;
cin>>s;

string ans;

codeToString(s,ans);

return 0;

}

hi @tarunkumar08yadav,

mere code mai ky galat hai

aur aapke wale code mai out.pop_back(ch) kisliye kiya hai

@tarunkumar08yadav pop_back(ch) helps to remove the last element from the vector

nhi samajh aaya pop kaise kaam kr rha hai

hi @tarunkumar08yadav vector k lectures dekhna you’ll get to know how it works, for now just know it helps to remove last element from the vector

#include <bits/stdc++.h> using namespace std; void solve(string inp,string out,int n,int i) { if(i==n) { cout<<out<<endl;; return; } int digit=inp[i]-‘0’; char ch=‘a’+digit-1; out.push_back(ch); solve(inp,out,n,i+1); out.pop_back(); if(i+1<n) { int digit2=inp[i+1]-‘0’; int no=digit*10+digit2; if(no<=26) { char ch=‘a’+no-1; out.push_back(ch); solve(inp,out,n,i+2); out.pop_back(); } } } int main() { string inp; cin>>inp; int n=inp.size(); string out; solve(inp,out,n,0); }

abhi bhi test cases pr pass nhi ho raha hai

hi @tarunkumar08yadav dont print comma after last element do this small change

for(int i=0;i<v.size();i++)
	{
		cout<<v[i];
		if(i != v.size()-1)cout<<", ";
	}