Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. int x[100],k; char cuv[50][50];
  5. void init()
  6. {
  7. x[k]=0;
  8. }
  9. bool amsuccesor()
  10. {
  11. if(x[k]<5){x[k]++;
  12. return true;}
  13. return false;
  14. }
  15. bool evalid()
  16. {
  17.  
  18. if(x[k-1]==x[k]) return false;
  19. if(x[k]==1&&x[k-1]==2||x[k]==2&&x[k-1]==1||x[k]==3&&x[k-1]==1||x[k]==1&&x[k-1]==3||x[k]==2&&x[k-1]==3||x[k]==3&&x[k-1]==2 || x[k]==5&&x[k-1]==4 || x[k]==4&&x[k-1]==5) return false;
  20. return true;
  21.  
  22. }
  23. bool solutie()
  24. {
  25. if(k==2) return true;
  26. return false;
  27. }
  28. void tipar()
  29. {
  30. int i;
  31. for(i=1;i<=2;i++)
  32. cout<<cuv[x[i]]<<" ";
  33. cout<<endl;
  34. }
  35. void back()
  36. {
  37. k=1;init();
  38. bool as,ev;
  39. while(k>0)
  40. {
  41. do{as=amsuccesor();
  42. ev=evalid();}
  43. while(as==1&&ev==0);
  44. if(as==1)
  45. if(solutie()==1)tipar();
  46. else{k++; init();}else k--;
  47. }
  48. }
  49. int main()
  50. {
  51. strcpy(cuv[1],"Maria");
  52. strcpy(cuv[2],"Ana");
  53. strcpy(cuv[3],"Doina");
  54. strcpy(cuv[4],"Doru");
  55. strcpy(cuv[5],"Cosmin");
  56. back();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement