fork download
  1. #include <iostream>
  2. using namespace std;
  3. int k=0;
  4. int fnct(string input, int index, string output, string out[]) {
  5. if (index >= input.length()){
  6. out[k++] = output;
  7. return 1;
  8. }
  9. int number = input[index]-'0';
  10. int count=fnct(input, index+1, output+(char)('a'+ number-1),out);
  11. if(index<input.length()-1){
  12. number = number*10 + input[index+1]-'0';
  13. if(number < 26) {
  14. count+=fnct(input, index+2, output+(char)('a'+ number-1),out);
  15. }
  16. }
  17. return count;
  18. }
  19.  
  20. void swap(char& a, char& b){
  21.  
  22. char temp = a;
  23. a=b;
  24. b=temp;
  25. }
  26.  
  27. void fn(string in, int index){
  28. if(index == in.length()){
  29. cout<<in<<endl;
  30. return;
  31. }
  32.  
  33. for(int i=index;i<in.length();++i){
  34. swap(in[index],in[i]);
  35. fn(in,index+1);
  36. swap(in[index],in[i]);
  37.  
  38. }
  39.  
  40. }
  41.  
  42. int main() {
  43. // your code goes here
  44. fn("abc",0) ;
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5472KB
stdin
Standard input is empty
stdout
abc
acb
bac
bca
cba
cab