Advertisement
Centipede18

Sinh Nhi Phan

Mar 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. void print(int arr[], int n){
  6.     for(int i = 1; i <= n; i++)
  7.     {
  8.         cout<<arr[i];
  9.     }
  10.     cout<<endl;
  11. }
  12.  
  13. void next(int arr[], int n){
  14.     int position = n;
  15.     while(position >= 1 && arr[position] == 1) position--;
  16.     arr[position] = 1;
  17.     for(int i = position+1; i < n; i++){
  18.         arr[position] = 0;
  19.     }
  20. }
  21.  
  22. main()
  23. {
  24.     int n, arr[100005]={0};
  25.     cin>>n;
  26.     int length=pow(2,n);
  27.     for(int i = 1; i < length; i++)
  28.     {
  29.         print(arr, n);
  30.         next(arr, n);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement