https://hack.codingblocks.com/contests/c/452/346
#include<bits/stdc++.h>
using namespace std;
vectorv;
void codes(string in ,string out)
{
if(in.size()==1)
{
v.push_back(out+(char)((int)(in.at(0) -'0'+ 'a') -1));
return;
}
codes(in.substr(1),out+(char)((int)(in.at(0) -'0'+ 'a') -1));
if(in.size()==2)
{
v.push_back(out+(char)((int)( (in.at(0) -'0')*10+ in.at(1) -'0' +'a') -1));
return;
}
if( (in[0]-'0')*10+(in[1]-'0')<=26){
if(in.size()>2)
codes(in.substr(2),out+(char)((int)( (in.at(0) -'0')*10+ in.at(1) -'0' +'a') -1) );
else if(in.size()==2)
v.push_back(out+(char)((int)( (in.at(0) -'0')*10+ in.at(1) -'0' +'a') -1));
}
}
int main(){
string inp;
cin>>inp;
codes(inp,"");
cout<<"["; copy(v.begin(),v.end(),ostream_iterator(cout,", “)) ;cout<<”\b\b]";
}
This code is passing the sample case. And even some of my own test cases.
In the question it mentioned that the the recursive func should return arraylist ,is it because of this?