Advertisement
AlexandruDu

Tema produs cartezian

Nov 8th, 2020
1,809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int n,x;
  5. char st[6];
  6. void tipar()
  7. {
  8.     for(int i=1;i<=n;i++)
  9.         cout<<st[i];
  10.     cout<<'\n';
  11.     x++;
  12. }
  13. bool valid(int k)
  14. {
  15.     if(strchr("AEIOU",st[k-1])&&strchr("AEIOU",st[k]))
  16.         return 0;
  17.     return 1;
  18. }
  19. bool sol(int k)
  20. {
  21.     return k==n;
  22. }
  23. void bt()
  24. {
  25.     int k=1;
  26.     st[k]=65;
  27.     while(k)
  28.     {
  29.         if(st[k]<90)
  30.         {
  31.             st[k]++;
  32.             if(valid(k))
  33.                 if(sol(k)) tipar();
  34.                 else st[++k]=65;
  35.         }
  36.         else k--;
  37.     }
  38. }
  39. int main()
  40. {
  41.     n=5;
  42.     bt();
  43.     cout<<x;
  44.     return 0;
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement