Advertisement
a53

cifre_bin_back

a53
Oct 7th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #define NR 1000
  3. using namespace std;
  4. int x[NR],n,nr1;
  5.  
  6. void afis()
  7. {
  8. int NR1=0;
  9. for(int i=1;i<=n;i++)
  10. if(x[i])
  11. ++NR1;
  12. if(NR1==nr1)
  13. {
  14. for(int i=1;i<=n;i++)
  15. cout<<x[i];
  16. cout<<'\n';
  17. }
  18. }
  19.  
  20. void back(int k)
  21. {
  22. for(int i=0;i<=1;++i)
  23. {
  24. x[k]=i;
  25. if(k==n)
  26. afis();
  27. else
  28. back(k+1);
  29. }
  30. }
  31.  
  32. int main()
  33. {
  34. cin>>n;
  35. int i=0;
  36. while(n)
  37. {
  38. if(n%2)
  39. ++nr1;
  40. ++i,n/=2;
  41. }
  42. n=i;
  43. back(1);
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement