Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int n;
- int solutie[20];
- char operatori[21];
- int sol_final[20];
- bool ok = true;
- void rezultat()
- {
- if (ok) {
- for (int i = 1; i <= n; ++i)
- sol_final[i] = solutie[i];
- ok = false;
- }
- }
- bool solutionare(int k)
- {
- if (k == n)
- return true;
- return false;
- }
- bool conditie(int k)
- {
- for (int i = 1; i < k; ++i)
- {
- if (operatori[i - 1] == '>')
- if (solutie[i] < solutie[i + 1]) return false;
- else if(operatori[i - 1] == '<')
- if (solutie[i] > solutie[i + 1]) return false;
- }
- for (int i = 1; i < k; ++i)
- if (solutie[i] == solutie[k])
- return false;
- return true;
- }
- void bt(int k)
- {
- for (int i = 1; i <= n; ++i)
- {
- solutie[k] = i;
- if (conditie(k))
- {
- if (solutionare(k))
- rezultat();
- else
- bt(k + 1);
- }
- }
- }
- int main()
- {
- cin >> operatori;
- n = strlen(operatori) + 1;
- bt(1);
- for (int i = 1; i <= n; ++i)
- cout << sol_final[i] << ' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement