Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <stack>
  2. #include <iostream>
  3. #include <string>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     string wyraz;
  14.  
  15.  
  16.     stack <char> stos;
  17.  
  18.     cin >> wyraz;
  19.  
  20.  
  21.     int dlugosc_wyrazu = wyraz.length();
  22.     for (int i = 0; i < dlugosc_wyrazu; i++)
  23.     {
  24.         if (wyraz[i] == 't' || wyraz[i] == 'f')
  25.         {
  26.             stos.push(wyraz[i]);
  27.         }
  28.         else if (wyraz[i] == 'K')
  29.         {
  30.             int w1, w2, w3;
  31.  
  32.             if (stos.top() == 't')
  33.             {
  34.                 w1 = 1;
  35.                 stos.pop();
  36.             }
  37.             else if (stos.top() == 'f')
  38.             {
  39.                 w1 = 0;
  40.                 stos.pop();
  41.             }
  42.  
  43.             if (stos.top() == 't')
  44.             {
  45.                 w2 = 1;
  46.                 stos.pop();
  47.             }
  48.             else if (stos.top() == 'f')
  49.             {
  50.                 w2 = 0;
  51.                 stos.pop();
  52.             }
  53.  
  54.             w3 = w1 && w2;
  55.  
  56.             if (w3 == 1)
  57.             {
  58.                 stos.push('t');
  59.             }
  60.             else
  61.             {
  62.                 stos.push('f');
  63.             }
  64.         }
  65.         else if (wyraz[i] == 'A')
  66.         {
  67.             int w1, w2, w3;
  68.  
  69.             if (stos.top() == 't')
  70.             {
  71.                 w1 = 1;
  72.                 stos.pop();
  73.             }
  74.             else
  75.             {
  76.                 w1 = 0;
  77.                 stos.pop();
  78.             }
  79.  
  80.             if (stos.top() == 't')
  81.             {
  82.                 w2 = 1;
  83.                 stos.pop();
  84.             }
  85.             else
  86.             {
  87.                 w2 = 0;
  88.                 stos.pop();
  89.             }
  90.  
  91.             w3 = w1 || w2;
  92.  
  93.             if (w3 == 1)
  94.             {
  95.                 stos.push('t');
  96.             }
  97.             else
  98.             {
  99.                 stos.push('f');
  100.             }
  101.         }
  102.         else if (wyraz[i] == 'N')
  103.         {
  104.             if (stos.top() == 't')
  105.             {
  106.  
  107.                 stos.pop();
  108.                 stos.push('f');
  109.             }
  110.             else
  111.             {
  112.                 stos.pop();
  113.                 stos.push('t');
  114.             }
  115.         }
  116.  
  117.  
  118.     }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.     cout << stos.top();
  128.  
  129.  
  130.  
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement