fork download
  1. #include <iostream>
  2. using namespace std;
  3. int getCodes(string input,string output[1000])
  4. {
  5. if(input[0]=='\0')
  6. {
  7. return 1;
  8. }
  9. char a=('a'+(int)(input[0]-'0')-1);
  10. char b=('a'+(int)(input[0]-'0')*10+(int)(input[1]-'0')-1);
  11. string output1[1000];
  12. string output2[1000];
  13. int count1=getCodes(input.substr(1),output1);
  14. for(int i=0;i<count1;i++)
  15. {
  16. output1[i]=a+output1[i];
  17. }
  18. int count2=0;
  19. if(b>='j'&&b<='z')
  20. {
  21. count2=getCodes(input.substr(2),output2);
  22.  
  23. }
  24.  
  25. for(int i=0;i<count2;i++)
  26. {
  27. output2[i]=b+output2[i];
  28. }
  29. for(int i=0;i<count1;i++)
  30. {
  31. output[i]=output1[i];
  32. }
  33. for(int j=0;j<count2;j++)
  34. {
  35. output[j+count1]=output2[j];
  36. }
  37. return count1+count2;
  38. }
  39. int main() {
  40. // your code goes here
  41. string input;
  42. cin>>input;
  43. string output[2000];
  44. int count=getCodes(input,output);
  45. for(int i=0;i<count&&i<2000;i++)
  46. {
  47. cout<<output[i]<<endl;
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0s 5436KB
stdin
1123
stdout
aabc
aaw
alc
kbc
kw