fork download
  1.  
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. void generuj_permutacje(string zrodlo, string tworzacy)
  7. {
  8. if(zrodlo.length() == 0)
  9. {
  10. cout << tworzacy << endl;
  11. }
  12. else
  13. for (int i = 0; i < zrodlo.length(); i++)
  14. {
  15. string noweZrodlo = zrodlo;
  16. string nowyTworzacy = tworzacy + zrodlo[i];
  17. noweZrodlo.erase(i, 1);
  18. generuj_permutacje(noweZrodlo, nowyTworzacy);
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. string zrodlo = "abcd";
  25. string tworzacy = "";
  26. generuj_permutacje(zrodlo, tworzacy);
  27. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
abcd
abdc
acbd
acdb
adbc
adcb
bacd
badc
bcad
bcda
bdac
bdca
cabd
cadb
cbad
cbda
cdab
cdba
dabc
dacb
dbac
dbca
dcab
dcba