Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <climits>
  4. #include <vector>
  5. #include <string>
  6. #include <math.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main(){
  12. //ios_base::sync_with_stdio(0);
  13. //cin.tie(0);
  14. //freopen("chaincode.in", "r", stdin);
  15. //freopen("chaincode.out", "w", stdout);
  16. int n,j=0;
  17. cin>>n;
  18. string s,pref;
  19. int m=pow(2,n);
  20. for (int i=0; i<n; i++)
  21. s[i] = '0';
  22. string a[m];
  23. cout<<s<<"\n";
  24. a[j]++ = s;
  25. bool f = true;
  26. while (f){
  27. f = false;
  28. pref = s;
  29. pref.substr(1,n-1);
  30. for (int i=0; i<m; i++){
  31. if (a[i]==pref+"1"){
  32. break;
  33. }
  34. else{
  35. s = pref+"1";
  36. f = true;
  37. }
  38. for (int i=0; i<m; i++){
  39. if (a[i]==pref+"0"){
  40. break;
  41. }
  42. else{
  43. s = pref+"0";
  44. f = true;
  45. }
  46. }
  47. cout<<s<<"\n";
  48. a[j++]=s;
  49. }
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement