Advertisement
rofllmaolol

steaguri

Feb 26th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <cstring>
  2. #include <fstream>
  3. #include <iomanip>
  4. using namespace std;
  5. ofstream fout("iesire.txt");
  6. char culoare[7][20];
  7. int st[200];
  8. int k;
  9. void add ()
  10. {
  11.     strcpy (culoare[1], "galben");
  12.     strcpy (culoare[2], "rosu");
  13.     strcpy (culoare[3], "verde");
  14.     strcpy (culoare[4], "albastru");
  15.     strcpy (culoare[5], "alb");
  16.     strcpy (culoare[6], "negru");
  17. }
  18. int sol ()
  19. {
  20.     return (k==3);
  21. }
  22. void tipar ()
  23. {
  24.     for (int j=1; j<=k; j++)
  25.         fout << setw(10)<<culoare[st[j]]<< " ";
  26.     fout << endl;
  27. }
  28. int validare ()
  29. {
  30.     if (k==2)
  31.         if ( (st[k]!=3)&&(st[k]!=1))
  32.             return 0;
  33.     for (int i=1; i<=k-1; i++)
  34.         if (st[k]==st[i])
  35.             return 0;
  36.     return 1;
  37.  
  38. }
  39. void bt ()
  40. {
  41.     for (k=1; k<=6; k++)
  42.         st[k]=0;
  43.     k=1;
  44.     while (k>0)
  45.     {
  46.         while (st[k]<6)
  47.         {
  48.             st[k] ++;
  49.             if (validare()){
  50.                 if (sol())
  51.                     tipar ();
  52.                 else
  53.                     k++;}
  54.         }
  55.         st[k--]=0;
  56.     }
  57. }
  58. int main ()
  59. {
  60.     add();
  61.     bt ();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement