Advertisement
niks1234

Untitled

Nov 6th, 2024
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | Source Code | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stack>
  5. using namespace std;
  6. int main() {
  7.     char s[1005];
  8.     int i, j;
  9.     while(scanf("%s", s) && s[0] != '0') {
  10.         int ret = 1, len = strlen(s);
  11.         int a, b;
  12.         for(i = 0; i < 32; i++) {
  13.             stack<int> stk;
  14.             for(j = len-1; j >= 0; j--) {
  15.                 if(s[j] >= 'p') {
  16.                     int val = (i>>(s[j]-'p'))&1;
  17.                     stk.push(val);
  18.                 } else {
  19.                     a = stk.top(), stk.pop();
  20.                     if(s[j] != 'N') {
  21.                         b = stk.top(), stk.pop();
  22.                     }
  23.                     if(s[j] == 'K')
  24.                         stk.push(a&b);
  25.                     if(s[j] == 'A')
  26.                         stk.push(a|b);
  27.                     if(s[j] == 'N')
  28.                         stk.push(!a);
  29.                     if(s[j] == 'C')
  30.                         stk.push(!(a&(!b)));
  31.                     if(s[j] == 'E')
  32.                         stk.push(a == b);
  33.                 }
  34.             }
  35.             ret &= stk.top();
  36.         }
  37.         puts(ret ? "tautology" : "not");
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement