fork download
  1. #include <iostream>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. using namespace std;
  5. int count = 1;
  6. void swap (char *a, char *b)
  7. {
  8. char temp;
  9. temp = *a;
  10. *a = *b;
  11. *b = temp;
  12. }
  13. int permute(string a, int l, int r,string b)
  14. {
  15. int i;
  16. if(l==r)
  17. {
  18. if(a == b){
  19. cout<<"\n"<<count;
  20. }
  21. count++;
  22. }
  23. else
  24. {
  25. for(i=l;i<=r;i++)
  26. {
  27. swap(a[l],a[i]);
  28. permute(a, l+1, r, b);
  29. swap(a[l],a[i]);
  30. }
  31. }
  32. }
  33. string sort(string a, int n)
  34. {
  35. int i,j;
  36. for(i=0;i<n-1;i++)
  37. {
  38. for(j=0;j<n-i-1;j++)
  39. {
  40. if(a[j]>a[j+1])
  41. {
  42. swap(a[j],a[j+1]);
  43. }
  44. }
  45. }
  46. return a;
  47. }
  48.  
  49. int main() {
  50. string a, b;
  51. int k, c;
  52. cin>>a;
  53. cin>>b;
  54. k = a.length();
  55. a = sort(a,k);
  56.  
  57. permute(a,0,k-1,b);
  58. return 0;
  59. }
Success #stdin #stdout 0s 3464KB
stdin
1234
3421
stdout
18