daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<fstream>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. ifstream cin("permrep.in");
  6. ofstream cout("permrep.out");
  7. char c[15],lit[15];
  8. int nr[15],w[15],x[15],n,N;
  9. void afis()
  10. {
  11.     for(int i=1;i<=N;i++) cout<<lit[x[i]];
  12.     cout<<'\n';
  13. }
  14. void bt(int k)
  15. {
  16.     for(int i=1;i<=n;i++)
  17.     {
  18.         if(w[i]<nr[i])
  19.         {
  20.             ++w[i];
  21.             x[k]=i;
  22.             if(k==N) afis();
  23.             else bt(k+1);
  24.             --w[i];
  25.         }
  26.  
  27.     }
  28. }
  29. int main()
  30. {
  31.     cin>>(c+1);
  32.     N=strlen(c+1);
  33.     sort(c+1,c+N+1);
  34.     for(int i=1;i<=N;i++)
  35.         if(c[i]==c[i-1]) ++nr[n];
  36.          else
  37.          {
  38.              nr[++n]=1;
  39.              lit[n]=c[i];
  40.          }
  41.     bt(1);
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top