Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //ifstream f("date.in");
  5. //ofstream g("date.out");
  6.  
  7. int n, x[101];
  8. void afisare() {
  9. for(int i=1; i <= n; i++) cout << x[i];
  10. cout << '\n';
  11. }
  12.  
  13. int bun(int i) {
  14. if(i == 1 and x[i] != 0) return 0;
  15. if(i == n and x[i] != 0) return 0;
  16. for(int j=1; j<i; j++)
  17. if(abs(x[j]-x[j+1]) != 1) return 0;
  18. return 1;
  19. }
  20.  
  21. void back(int i) {
  22. while(i) {
  23. x[i]++;
  24. if(x[i] == n) x[i] = -1, i--;
  25. else if(bun(i)) {
  26. if(i == n) afisare();
  27. else i++;
  28. }
  29. }
  30. }
  31.  
  32. int main() {
  33. cin >> n;
  34. for(int i=1; i<=n; i++) x[i] = -1;
  35. x[1] = 0;
  36. back(2);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement