Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stack>
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string wyraz;
- stack <char> stos;
- cin >> wyraz;
- int dlugosc_wyrazu = wyraz.length();
- for (int i = 0; i < dlugosc_wyrazu; i++)
- {
- if (wyraz[i] == 't' || wyraz[i] == 'f')
- {
- stos.push(wyraz[i]);
- }
- else if (wyraz[i] == 'K')
- {
- int w1, w2, w3;
- if (stos.top() == 't')
- {
- w1 = 1;
- stos.pop();
- }
- else if (stos.top() == 'f')
- {
- w1 = 0;
- stos.pop();
- }
- if (stos.top() == 't')
- {
- w2 = 1;
- stos.pop();
- }
- else if (stos.top() == 'f')
- {
- w2 = 0;
- stos.pop();
- }
- w3 = w1 && w2;
- if (w3 == 1)
- {
- stos.push('t');
- }
- else
- {
- stos.push('f');
- }
- }
- else if (wyraz[i] == 'A')
- {
- int w1, w2, w3;
- if (stos.top() == 't')
- {
- w1 = 1;
- stos.pop();
- }
- else
- {
- w1 = 0;
- stos.pop();
- }
- if (stos.top() == 't')
- {
- w2 = 1;
- stos.pop();
- }
- else
- {
- w2 = 0;
- stos.pop();
- }
- w3 = w1 || w2;
- if (w3 == 1)
- {
- stos.push('t');
- }
- else
- {
- stos.push('f');
- }
- }
- else if (wyraz[i] == 'N')
- {
- if (stos.top() == 't')
- {
- stos.pop();
- stos.push('f');
- }
- else
- {
- stos.pop();
- stos.push('t');
- }
- }
- }
- cout << stos.top();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement