Created
April 16, 2018 15:24
-
-
Save Zyro9922/1892cb52846b30d9c52bc3f9c7816364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
char digToChar(int n) | |
{ | |
return n + 'a' - 1; | |
} | |
void stringCodes(char inp[], int be, char ansSoFar[], int i) | |
{ | |
if(inp[be] == '\0') | |
{ | |
ansSoFar[i] = '\0'; // dabba band karna na bhule | |
cout<<ansSoFar<<", "; | |
return; | |
} | |
// simple print | |
int num = inp[be] - '0'; | |
char ch = digToChar(num); | |
ansSoFar[i] = ch; | |
stringCodes(inp, be+1, ansSoFar, i+1); | |
// | |
if(inp[be+1] != '\0') | |
{ | |
int n = (inp[be]-'0')*10 + inp[be+1]-'0'; | |
if(n <= 26) | |
{ | |
ansSoFar[i] = digToChar(n); | |
stringCodes(inp, be+2, ansSoFar, i+1); | |
} | |
} | |
else | |
return; | |
} | |
int main() | |
{ | |
char inp[10]; | |
cin>>inp; | |
char ansSoFar[10]; | |
cout<<"["; | |
stringCodes(inp, 0, ansSoFar, 0); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment