Advertisement
aimon1337

Untitled

Apr 14th, 2021
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int n;
  6. int solutie[20];
  7. char operatori[21];
  8. int sol_final[20];
  9. bool ok = true;
  10.  
  11. void rezultat()
  12. {
  13.     if (ok) {
  14.         for (int i = 1; i <= n; ++i)
  15.             sol_final[i] = solutie[i];
  16.         ok = false;
  17.     }
  18. }
  19.  
  20. bool solutionare(int k)
  21. {
  22.     if (k == n)
  23.         return true;
  24.     return false;
  25. }
  26.  
  27. bool conditie(int k)
  28. {
  29.     for (int i = 1; i < k; ++i)
  30.     {
  31.         if (operatori[i - 1] == '>')
  32.             if (solutie[i] < solutie[i + 1]) return false;
  33.         else if(operatori[i - 1] == '<')
  34.             if (solutie[i] > solutie[i + 1]) return false;
  35.     }
  36.     for (int i = 1; i < k; ++i)
  37.         if (solutie[i] == solutie[k])
  38.             return false;
  39.     return true;
  40. }
  41.  
  42. void bt(int k)
  43. {
  44.     for (int i = 1; i <= n; ++i)
  45.     {
  46.         solutie[k] = i;
  47.         if (conditie(k))
  48.         {
  49.             if (solutionare(k))
  50.                 rezultat();
  51.             else
  52.                 bt(k + 1);
  53.         }
  54.     }
  55. }
  56.  
  57. int main()
  58. {
  59.     cin >> operatori;
  60.     n = strlen(operatori) + 1;
  61.     bt(1);
  62.     for (int i = 1; i <= n; ++i)
  63.         cout << sol_final[i] << ' ';
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement