SHARE
TWEET

Untitled

a guest Oct 21st, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. ifstream in ("permutari2.in");
  5. ofstream out ("permutari2.out");
  6.  
  7. int n, x[10], v[10];
  8.  
  9. int valid (int i)
  10. {
  11.     for (int k=1; k<i; k++)
  12.         if (v[k]==v[i])
  13.             return 0;
  14.     return 1;
  15. }
  16.  
  17. void afis()
  18. {
  19.     for (int k=1; k<=n; k++)
  20.         out<<x[v[k]]<<" ";
  21.     out<<endl;
  22. }
  23.  
  24. void Back ()
  25. {
  26.     int i=1;
  27.     while (i)
  28.     {
  29.         v[i]++;
  30.         if (v[i]>n)
  31.         {
  32.             v[i]=0;
  33.             i--;
  34.         }
  35.         else
  36.             if (valid(i))
  37.             {
  38.                 if (i==n)
  39.                     afis();
  40.                 i++;
  41.             }
  42.     }
  43.  
  44. }
  45.  
  46. int main()
  47. {
  48.     in>>n;
  49.     for(int i=1; i<=n; i++)
  50.         in>>x[i];
  51.     sort(x+1, x+n+1);
  52.     Back ();
  53.     return 0;
  54. }
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