Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void back(int k);
- void tipar(int k);
- int valid(int k);
- int n,k,stiva[20];
- int main()
- {
- ifstream f("pr2.in");
- f>>n;
- back(1);
- f.close();
- return 1;
- }
- void back(int k)
- {
- for(int val=1;val<=2*n;val++)
- {
- stiva[k]=val;
- if(valid(k))
- if(k==2*n)
- tipar(k);
- else
- back (k+1);
- }
- }
- bool acelasi_sex(int a,int b)
- {
- if(a%2==0 && a-b==1) return true;
- if(a%2==1 && b-1==1) return true;
- return false;
- }
- bool aceeasi_paritate(int a,int b)
- {
- if(a%2==0 && b%2==0) return true;
- if(a%2==1 && b%2==1) return true;
- return false;
- }
- int valid(int k)
- {
- if(k==1) return 1;
- for(int i=1;i<k;i++)
- if(stiva[i]==stiva[k]){cout<<"stiva[i]==stiva[k]\n"; return 0;}
- if(!acelasi_sex(stiva[k-1],stiva[k])){cout<<"acelasi_sex(stiva[k-1],stiva[k])\n"; return 0;}
- if(!aceeasi_paritate(stiva[k-1],stiva[k])){cout<<"aceeasi_paritate(stiva[k-1],stiva[k])\n"; return 0;}
- return 1;
- }
- void tipar(int k)
- {
- if(!acelasi_sex(stiva[1],stiva[k]) && !aceeasi_paritate(stiva[1],stiva[k]))
- {
- cout<<endl;
- for(int i=1;i<=k;i++)
- cout<<stiva[i]<<" ";
- }
- else cout<<"!!!acelasi_sex(stiva[1],stiva[k]) && !aceeasi_paritate(stiva[1],stiva[k]))\n";
- }
Add Comment
Please, Sign In to add comment