Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- int n; char v[20];
- int cont(int k){
- for(int i=1;i<k;i++){
- if(v[i]==v[k])
- return 0;
- if(v[k-1]==v[k]-1 || v[k-1]==v[k]+1)
- continue;
- else
- return 0;
- }
- return 1;
- }
- int sol(int k){
- return k==n;
- }
- int afisare(int k){
- for(int i=1;i<=k;i++)
- cout<<v[i];
- cout<<" ";
- }
- int back(int k){
- for(int i=65;i<=90;i++){
- v[k]=(char)i;
- if(cont(k))
- if(sol(k))
- afisare(k);
- else
- back(k+1);
- }
- }
- int main (){
- cin>>n;
- back(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement