Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <climits>
- #include <vector>
- #include <string>
- #include <math.h>
- using namespace std;
- int main(){
- //ios_base::sync_with_stdio(0);
- //cin.tie(0);
- //freopen("chaincode.in", "r", stdin);
- //freopen("chaincode.out", "w", stdout);
- int n,j=0;
- cin>>n;
- string s,pref;
- int m=pow(2,n);
- for (int i=0; i<n; i++)
- s[i] = '0';
- string a[m];
- cout<<s<<"\n";
- a[j]++ = s;
- bool f = true;
- while (f){
- f = false;
- pref = s;
- pref.substr(1,n-1);
- for (int i=0; i<m; i++){
- if (a[i]==pref+"1"){
- break;
- }
- else{
- s = pref+"1";
- f = true;
- }
- for (int i=0; i<m; i++){
- if (a[i]==pref+"0"){
- break;
- }
- else{
- s = pref+"0";
- f = true;
- }
- }
- cout<<s<<"\n";
- a[j++]=s;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement